]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2002 adds ETag support to simple cache handler
authorCash Costello <cash.costello@gmail.com>
Sun, 8 Jan 2012 15:06:58 +0000 (10:06 -0500)
committerCash Costello <cash.costello@gmail.com>
Sun, 8 Jan 2012 15:06:58 +0000 (10:06 -0500)
engine/handlers/cache_handler.php

index 94a0e64e9fced5ff01d731edcf08865eac0a6235..b332ec379f74debbd76ea86c82243887b3ae34f8 100644 (file)
@@ -60,26 +60,31 @@ preg_match($regex, $request, $matches);
 $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)) {