Skip to content

Commit

Permalink
Change caching checks for minimized files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bartv2 committed Sep 7, 2012
1 parent ff42da5 commit cd4b8db
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lib/minimizer.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
<?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);

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);
Expand All @@ -48,8 +45,8 @@ public function output($files, $cache_key) {

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');
}
}

Expand Down

0 comments on commit cd4b8db

Please sign in to comment.