Skip to content
Snippets Groups Projects
Commit cd4b8dba authored by Bart Visscher's avatar Bart Visscher
Browse files

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.
parent ff42da58
No related branches found
No related tags found
No related merge requests found
<?php
abstract class OC_Minimizer {
public function getLastModified($files) {
$last_modified = 0;
public function generateETag($files) {
$etag = '';
sort($files);
foreach($files as $file_info) {
$file = $file_info[0] . '/' . $file_info[2];
$filemtime = filemtime($file);
if ($filemtime > $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');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment