Change caching checks for minimized files

Only use a ETag, but include last modified time into this
Also added the filesize to this. And used the ETag for the
internal cache.
remotes/origin/stable45
Bart Visscher 13 years ago
parent ff42da58b9
commit cd4b8dbacd
  1. 27
      lib/minimizer.php

@ -1,16 +1,15 @@
<?php <?php
abstract class OC_Minimizer { abstract class OC_Minimizer {
public function getLastModified($files) { public function generateETag($files) {
$last_modified = 0; $etag = '';
sort($files);
foreach($files as $file_info) { foreach($files as $file_info) {
$file = $file_info[0] . '/' . $file_info[2]; $file = $file_info[0] . '/' . $file_info[2];
$filemtime = filemtime($file); $stat = stat($file);
if ($filemtime > $last_modified) { $etag .= $file.$stat['mtime'].$stat['size'];
$last_modified = $filemtime;
}
} }
return $last_modified; return md5($etag);
} }
abstract public function minimizeFiles($files); abstract public function minimizeFiles($files);
@ -18,23 +17,21 @@ abstract class OC_Minimizer {
public function output($files, $cache_key) { public function output($files, $cache_key) {
header('Content-Type: '.$this->contentType); header('Content-Type: '.$this->contentType);
OC_Response::enableCaching(); OC_Response::enableCaching();
$last_modified = $this->getLastModified($files); $etag = $this->generateETag($files);
OC_Response::setLastModifiedHeader($last_modified); $cache_key .= '-'.$etag;
$gzout = false; $gzout = false;
$cache = OC_Cache::getGlobalCache(); $cache = OC_Cache::getGlobalCache();
if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){ if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){
OC_Response::setETagHeader($etag);
$gzout = $cache->get($cache_key.'.gz'); $gzout = $cache->get($cache_key.'.gz');
if ($gzout) {
OC_Response::setETagHeader(md5($gzout));
}
} }
if (!$gzout) { if (!$gzout) {
$out = $this->minimizeFiles($files); $out = $this->minimizeFiles($files);
$gzout = gzencode($out); $gzout = gzencode($out);
OC_Response::setETagHeader(md5($gzout));
$cache->set($cache_key.'.gz', $gzout); $cache->set($cache_key.'.gz', $gzout);
OC_Response::setETagHeader($etag);
} }
if ($encoding = OC_Request::acceptGZip()) { if ($encoding = OC_Request::acceptGZip()) {
header('Content-Encoding: '.$encoding); header('Content-Encoding: '.$encoding);
@ -48,8 +45,8 @@ abstract class OC_Minimizer {
public function clearCache() { public function clearCache() {
$cache = OC_Cache::getGlobalCache(); $cache = OC_Cache::getGlobalCache();
$cache->delete('core.css.gz'); $cache->clear('core.css');
$cache->delete('core.js.gz'); $cache->clear('core.js');
} }
} }

Loading…
Cancel
Save