Skip to content

Commit

Permalink
Fixes #2002 adds ETag support to simple cache handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cash committed Jan 8, 2012
1 parent 3b496d9 commit d213db7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions engine/handlers/cache_handler.php
Expand Up @@ -60,26 +60,31 @@
$type = $matches[1];
$viewtype = $matches[2];
$view = $matches[3];
$ts = $matches[4];

// If is the same ETag, content didn't changed.
$etag = $ts;
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
header("HTTP/1.1 304 Not Modified");
exit;
}

switch ($type) {
case 'css':
header("Content-type: text/css", true);
header('Expires: ' . date('r', strtotime("+6 months")), true);
header("Pragma: public", true);
header("Cache-Control: public", true);

$view = "css/$view";
break;
case 'js':
header('Content-type: text/javascript', true);
header('Expires: ' . date('r', strtotime("+6 months")), true);
header("Pragma: public", true);
header("Cache-Control: public", true);

$view = "js/$view";
break;
}

header('Expires: ' . date('r', strtotime("+6 months")), true);
header("Pragma: public", true);
header("Cache-Control: public", true);
header("ETag: $etag");

$filename = $dataroot . 'views_simplecache/' . md5($viewtype . $view);

if (file_exists($filename)) {
Expand Down

0 comments on commit d213db7

Please sign in to comment.