Skip to content

Commit

Permalink
Cache bust some frequently updated assets (#3042)
Browse files Browse the repository at this point in the history
* Cache bust some frequently updated assets
* Clear asset cache during AutoUpdate
  • Loading branch information
mitchray committed Oct 13, 2021
1 parent 221e07c commit 88797f8
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -28,6 +28,7 @@ public/develop
public/master
public/foam
public/ample
public/cached_assets/
storage/
tmp/
/vendor/
Expand Down
7 changes: 4 additions & 3 deletions public/templates/header.inc.php
Expand Up @@ -28,6 +28,7 @@
use Ampache\Module\System\AutoUpdate;
use Ampache\Module\System\Core;
use Ampache\Module\Util\AjaxUriRetrieverInterface;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Mailer;
use Ampache\Module\Util\Ui;
use Ampache\Repository\PrivateMessageRepositoryInterface;
Expand Down Expand Up @@ -99,9 +100,9 @@
<script src="<?php echo $web_path; ?>/lib/components/jQuery-File-Upload/js/jquery.iframe-transport.js" defer></script>
<script src="<?php echo $web_path; ?>/lib/components/jQuery-File-Upload/js/jquery.fileupload.js" defer></script>
<script src="<?php echo $web_path; ?>/lib/components/jQuery-contextMenu/dist/jquery.contextMenu.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js" defer></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js" defer></script>
<script src="<?php echo $web_path; ?>/lib/javascript/tools.js" defer></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/base.js'); ?>" defer></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/ajax.js'); ?>" defer></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/tools.js'); ?>" defer></script>

<script>
$(document).ready(function(){
Expand Down
2 changes: 1 addition & 1 deletion public/templates/install_footer.inc.php
Expand Up @@ -4,7 +4,7 @@
================================================== -->
<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/components/bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js"></script>
<script src="<?php echo AssetCache::asset_url($web_path . '/lib/javascript/base.js'); ?>"></script>
<?php
if (isset($jsEnd) && !empty($jsEnd) && is_array($jsEnd)) {
foreach ($jsEnd as $js) {
Expand Down
3 changes: 3 additions & 0 deletions public/templates/show_debug.inc.php
Expand Up @@ -52,6 +52,9 @@
<li>
<a href="<?php echo $web_path; ?>/admin/system.php?action=clear_cache&type=album"><?php echo Ui::get_icon('cog', T_('Clear Albums Cache')) . ' ' . T_('Clear Albums Cache'); ?></a>
</li>
<li>
<a href="<?php echo $web_path; ?>/admin/system.php?action=clear_cache&type=asset"><?php echo Ui::get_icon('cog', T_('Clear Assets Cache')) . ' ' . T_('Clear Assets Cache'); ?></a>
</li>
</ul>
</div>

Expand Down
7 changes: 4 additions & 3 deletions public/templates/show_html5_player_headers.inc.php
Expand Up @@ -4,6 +4,7 @@
use Ampache\Module\Broadcast\Broadcast_Server;
use Ampache\Module\Playback\Stream;
use Ampache\Module\Util\AjaxUriRetrieverInterface;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Ui;

global $dic;
Expand All @@ -29,9 +30,9 @@
<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/components/jquery-ui/jquery-ui.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/components/js-cookie/js-cookie-built.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/tools.js"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/base.js'); ?>"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/ajax.js'); ?>"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/tools.js'); ?>"></script>
<script>
var jsAjaxServer = "<?php echo $ajaxUriRetriever->getAjaxServerUri(); ?>";
var jsAjaxUrl = "<?php echo $ajaxUriRetriever->getAjaxUri(); ?>";
Expand Down
5 changes: 3 additions & 2 deletions public/templates/show_registration_confirmation.inc.php
Expand Up @@ -21,6 +21,7 @@
*/

use Ampache\Config\AmpConfig;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Ui;

$htmllang = str_replace("_", "-", AmpConfig::get('lang'));
Expand All @@ -42,8 +43,8 @@
<a href="<?php echo $web_path; ?>"><h1 id="headerlogo"></h1></a>
</div>
<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/base.js'); ?>"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/ajax.js'); ?>"></script>
<div id="content">
<div id="guts">
<?php
Expand Down
5 changes: 3 additions & 2 deletions public/templates/show_user_activate.inc.php
Expand Up @@ -21,6 +21,7 @@
*/

use Ampache\Config\AmpConfig;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Ui;

$htmllang = str_replace("_", "-", AmpConfig::get('lang'));
Expand All @@ -41,8 +42,8 @@
<span><?php echo T_('Registration Validation'); ?>.</span>
</div>
<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/base.js'); ?>"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/ajax.js'); ?>"></script>
<div>
<?php
if ($validationResult) {
Expand Down
5 changes: 3 additions & 2 deletions public/templates/show_user_registration.inc.php
Expand Up @@ -25,6 +25,7 @@
use Ampache\Module\System\AmpError;
use Ampache\Module\System\Core;
use Ampache\Module\User\Registration;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Captcha\captcha;
use Ampache\Module\Util\Ui;

Expand All @@ -49,8 +50,8 @@

<body id="registerPage">
<script src="<?php echo $web_path; ?>/lib/components/jquery/jquery.min.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/base.js"></script>
<script src="<?php echo $web_path; ?>/lib/javascript/ajax.js"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/base.js'); ?>"></script>
<script src="<?php echo AssetCache::get_url($web_path . '/lib/javascript/ajax.js'); ?>"></script>

<div id="maincontainer">
<div id="header">
Expand Down
11 changes: 6 additions & 5 deletions public/templates/stylesheets.inc.php
Expand Up @@ -21,6 +21,7 @@
*/

use Ampache\Config\AmpConfig;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\Ui;

$web_path = AmpConfig::get('web_path');
Expand All @@ -31,16 +32,16 @@
$theme_css_base = array($theme_css_base);
}
foreach ($theme_css_base as $css_base) { ?>
<link rel="stylesheet" href="<?php echo $web_path . $theme_path . '/' . $css_base[0]; ?>" type="text/css" media="<?php echo $css_base[1]; ?>" />
<link rel="stylesheet" href="<?php echo AssetCache::get_url($web_path . $theme_path . '/' . $css_base[0]); ?>" type="text/css" media="<?php echo $css_base[1]; ?>" />
<?php
} ?>
<link rel="stylesheet" href="<?php echo $web_path . '/templates/base.css'; ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path . $theme_path . '/' . $theme_color . '.css'; ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path . '/templates/print.css'; ?>" type="text/css" media="print" />
<link rel="stylesheet" href="<?php echo AssetCache::get_url($web_path . '/templates/base.css'); ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo AssetCache::get_url($web_path . $theme_path . '/' . $theme_color . '.css'); ?>" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo AssetCache::get_url($web_path . '/templates/print.css'); ?>" type="text/css" media="print" />
<?php
if (is_rtl(AmpConfig::get('lang'))
&& is_file(__DIR__ . '/../../public/' . $theme_path . '/rtl.css')) { ?>
<link rel="stylesheet" href="<?php echo $web_path . $theme_path; ?>/rtl.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo AssetCache::get_url($web_path . $theme_path . '/rtl.css'); ?>" type="text/css" media="screen" />
<?php } ?>
<link rel="stylesheet" href="<?php echo $web_path; ?>/lib/components/prettyphoto/css/prettyPhoto.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php echo $web_path . '/templates/jquery-ui.custom.css'; ?>" type="text/css" media="screen" />
Expand Down
14 changes: 7 additions & 7 deletions public/themes/reborn/templates/dark.css
Expand Up @@ -128,7 +128,7 @@ input[type=submit]:focus:active {
-------------------------- */
#ajax-loading {
color: #ff9d00;
background-image: url(../images/ajax-loader.gif);
background-image: url(/themes/reborn/images/ajax-loader.gif);
}

/* --------------------------
Expand Down Expand Up @@ -173,7 +173,7 @@ input[type=submit]:focus:active {

#loginPage #headerlogo,
#registerPage #headerlogo {
background-image: url('../images/ampache-dark.png');
background-image: url('/themes/reborn/images/ampache-dark.png');
}

#loginPage #loginbox {
Expand Down Expand Up @@ -452,7 +452,7 @@ input:invalid {
}

#content .missing {
background-image: url('../images/missing.png');
background-image: url('/themes/reborn/images/missing.png');
}

/* --------------------------
Expand Down Expand Up @@ -497,7 +497,7 @@ span.fatalerror {
}

.item_art .item_art_play .item_art_play_icon {
background-image: url('../images/videoplay.png');
background-image: url('/themes/reborn/images/videoplay.png');
}

.item_art .item_art_actions {
Expand Down Expand Up @@ -532,12 +532,12 @@ span.fatalerror {

.userflag a.userflag_true,
.userflag a:hover.userflag_false {
background: url(../../../images/icon_flag.png) left top;
background: url(/images/icon_flag.png) left top;
}

.userflag a:hover.userflag_true,
.userflag a.userflag_false {
background: url(../../../images/icon_flag_off.png) left top;
background: url(/images/icon_flag_off.png) left top;
}

/* --------------------------
Expand Down Expand Up @@ -659,7 +659,7 @@ a.option-list:hover {
}

.editdialogstyle.ui-dialog {
background-image: url("../../../images/background.png") !important;
background-image: url("/images/background.png") !important;
}

#tabs li a {
Expand Down
8 changes: 4 additions & 4 deletions public/themes/reborn/templates/default.css
Expand Up @@ -22,7 +22,7 @@

@font-face {
font-family: 'DejaVuSansCondensed';
src: url('fonts/dejavusanscondensed.eot?') format('embedded-opentype'), url('fonts/dejavusanscondensed.woff') format('woff'), url('fonts/dejavusanscondensed.ttf') format('truetype'), url('fonts/dejavusanscondensed.svg#DejaVuSansCondensed') format('svg');
src: url('/themes/reborn/templates/fonts/dejavusanscondensed.eot?') format('embedded-opentype'), url('/themes/reborn/templates/fonts/dejavusanscondensed.woff') format('woff'), url('/themes/reborn/templates/fonts/dejavusanscondensed.ttf') format('truetype'), url('/themes/reborn/templates/fonts/dejavusanscondensed.svg#DejaVuSansCondensed') format('svg');
}

/* --------------------------
Expand Down Expand Up @@ -1768,7 +1768,7 @@ span.fatalerror {
.star-rating ul,
.star-rating a:hover,
.star-rating .current-rating {
background: url(../images/ratings/star_rating.png) left -1000px repeat-x;
background: url(/themes/reborn/images/ratings/star_rating.png) left -1000px repeat-x;
}

.star-rating ul {
Expand Down Expand Up @@ -1817,15 +1817,15 @@ span.fatalerror {
.star-rating a.star0 {
left: 0;
width: 16px;
background: url(../../../images/ratings/x_off.gif) left top;
background: url(/images/ratings/x_off.gif) left top;
}

.dynamic-star-rating a:hover {
background-position: left center;
}

.dynamic-star-rating a:hover.star0 {
background: url(../../../images/ratings/x.gif) left top;
background: url(/images/ratings/x.gif) left top;
}

.dynamic-star-rating ul {
Expand Down
18 changes: 9 additions & 9 deletions public/themes/reborn/templates/light.css
Expand Up @@ -126,7 +126,7 @@ input[type=submit]:focus:active {
------------------------ */
#ajax-loading {
color: #1990db;
background-image: url(../images/ajax-loader-light.gif);
background-image: url(/themes/reborn/images/ajax-loader-light.gif);
}

/* ------------------------
Expand Down Expand Up @@ -171,7 +171,7 @@ input[type=submit]:focus:active {

#loginPage #headerlogo,
#registerPage #headerlogo {
background-image: url('../images/ampache-light.png');
background-image: url('/themes/reborn/images/ampache-light.png');
}

#loginPage #loginbox {
Expand Down Expand Up @@ -454,7 +454,7 @@ input:invalid {
}

#content .missing {
background-image: url('../images/missing.png');
background-image: url('/themes/reborn/images/missing.png');
}

/* ------------------------
Expand Down Expand Up @@ -499,7 +499,7 @@ span.fatalerror {
}

.item_art .item_art_play .item_art_play_icon {
background-image: url('../images/videoplay.png');
background-image: url('/themes/reborn/images/videoplay.png');
}

.item_art .item_art_actions {
Expand Down Expand Up @@ -533,19 +533,19 @@ span.fatalerror {
}

.userflag a.userflag_true {
background: url(../../../images/icon_flag.png) left top;
background: url(/images/icon_flag.png) left top;
}

.userflag a:hover.userflag_true {
background: url(../../../images/icon_flag_off.png) left top;
background: url(/images/icon_flag_off.png) left top;
}

.userflag a.userflag_false {
background: url(../../../images/icon_flag_off.png) left top;
background: url(/images/icon_flag_off.png) left top;
}

.userflag a:hover.userflag_false {
background: url(../../../images/icon_flag.png) left top;
background: url(/images/icon_flag.png) left top;
}

/* ------------------------
Expand Down Expand Up @@ -669,7 +669,7 @@ a.option-list:hover {
}

.editdialogstyle.ui-dialog {
background-image: url("../../../images/background.light.png") !important;
background-image: url("/images/background.light.png") !important;
}

#tabs li a {
Expand Down
4 changes: 4 additions & 0 deletions src/Module/Application/Admin/System/ClearCacheAction.php
Expand Up @@ -33,6 +33,7 @@
use Ampache\Module\Application\Exception\AccessDeniedException;
use Ampache\Module\Authorization\AccessLevelEnum;
use Ampache\Module\Authorization\GuiGatekeeperInterface;
use Ampache\Module\Util\AssetCache;
use Ampache\Module\Util\UiInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -79,6 +80,9 @@ public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gat
case 'album':
Album::clear_cache();
break;
case 'asset':
AssetCache::clear_cache();
break;
}

$this->ui->showConfirmation(
Expand Down
2 changes: 2 additions & 0 deletions src/Module/System/AutoUpdate.php
Expand Up @@ -26,6 +26,7 @@

use Ampache\Config\AmpConfig;
use Ampache\Config\ConfigContainerInterface;
use Ampache\Module\Util\AssetCache;
use Exception;
use Ampache\Repository\Model\Preference;
use Requests;
Expand Down Expand Up @@ -314,6 +315,7 @@ public static function update_files($api = false)
if (!$api) {
echo T_('Done') . '<br />';
}
AssetCache::clear_cache();
ob_flush();
self::get_latest_version(true);
}
Expand Down

0 comments on commit 88797f8

Please sign in to comment.