Handle no-cache control in JavaScript and StyleSheet, not in FileCache

This commit is contained in:
Eric Lippmann 2015-11-27 16:51:19 +01:00
parent bac09fd125
commit 3a22168b64
2 changed files with 12 additions and 8 deletions

View File

@ -191,9 +191,6 @@ class FileCache
/** /**
* Whether the given ETag matchesspecific file(s) on disk * Whether the given ETag matchesspecific file(s) on disk
* *
* If no ETag is given we'll try to fetch the one from the current
* HTTP request. Respects HTTP Cache-Control: no-cache, if set.
*
* @param string|array $files file(s) to check * @param string|array $files file(s) to check
* @param string $match ETag to match against * @param string $match ETag to match against
* *
@ -209,9 +206,6 @@ class FileCache
if (! $match) { if (! $match) {
return false; return false;
} }
if (isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'no-cache') {
return false;
}
$etag = self::etagForFiles($files); $etag = self::etagForFiles($files);
return $match === $etag ? $etag : false; return $match === $etag ? $etag : false;

View File

@ -55,6 +55,13 @@ class JavaScript
self::send(); self::send();
} }
/**
* Send the client side script code to the client
*
* Does not cache the client side script code if the HTTP header Cache-Control or Pragma is set to no-cache.
*
* @param bool $minified Whether to compress the client side script code
*/
public static function send($minified = false) public static function send($minified = false)
{ {
header('Content-Type: application/javascript'); header('Content-Type: application/javascript');
@ -86,7 +93,10 @@ class JavaScript
} }
$files = array_merge($vendorFiles, $jsFiles); $files = array_merge($vendorFiles, $jsFiles);
if ($etag = FileCache::etagMatchesFiles($files)) { $request = Icinga::app()->getRequest();
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
if (! $noCache && FileCache::etagMatchesFiles($files)) {
header("HTTP/1.1 304 Not Modified"); header("HTTP/1.1 304 Not Modified");
return; return;
} else { } else {
@ -98,7 +108,7 @@ class JavaScript
$cacheFile = 'icinga-' . $etag . $min . '.js'; $cacheFile = 'icinga-' . $etag . $min . '.js';
$cache = FileCache::instance(); $cache = FileCache::instance();
if ($cache->has($cacheFile)) { if (! $noCache && $cache->has($cacheFile)) {
$cache->send($cacheFile); $cache->send($cacheFile);
return; return;
} }