From cd4b8dbacd04fc821b14534cb43e301e0d2255f1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 7 Sep 2012 13:40:04 +0200 Subject: [PATCH] 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. --- lib/minimizer.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/minimizer.php b/lib/minimizer.php index 6e425efad55..ff5f9304d9c 100644 --- a/lib/minimizer.php +++ b/lib/minimizer.php @@ -1,16 +1,15 @@ $last_modified) { - $last_modified = $filemtime; - } + $stat = stat($file); + $etag .= $file.$stat['mtime'].$stat['size']; } - return $last_modified; + return md5($etag); } abstract public function minimizeFiles($files); @@ -18,23 +17,21 @@ abstract class OC_Minimizer { public function output($files, $cache_key) { header('Content-Type: '.$this->contentType); OC_Response::enableCaching(); - $last_modified = $this->getLastModified($files); - OC_Response::setLastModifiedHeader($last_modified); + $etag = $this->generateETag($files); + $cache_key .= '-'.$etag; $gzout = false; $cache = OC_Cache::getGlobalCache(); if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)){ + OC_Response::setETagHeader($etag); $gzout = $cache->get($cache_key.'.gz'); - if ($gzout) { - OC_Response::setETagHeader(md5($gzout)); - } } if (!$gzout) { $out = $this->minimizeFiles($files); $gzout = gzencode($out); - OC_Response::setETagHeader(md5($gzout)); $cache->set($cache_key.'.gz', $gzout); + OC_Response::setETagHeader($etag); } if ($encoding = OC_Request::acceptGZip()) { header('Content-Encoding: '.$encoding); @@ -48,8 +45,8 @@ abstract class OC_Minimizer { public function clearCache() { $cache = OC_Cache::getGlobalCache(); - $cache->delete('core.css.gz'); - $cache->delete('core.js.gz'); + $cache->clear('core.css'); + $cache->clear('core.js'); } } -- 2.39.5