Tweak the cache implementation

1) Drop the *_modified key, we don't really need it.  The modification date is not
   relevant to our browser caching strategy.
2) Fix multiple issues with the Expires header and just hardcode it to the biggest
   possibly value for code clarity.
3) print the $content out directly instead of using fwrite
4) Minor cleanups in the installer.
This commit is contained in:
Bharat Mediratta
2009-06-28 16:24:51 -07:00
parent f3f8b5eed6
commit aa31e1f009
3 changed files with 33 additions and 36 deletions

View File

@@ -27,16 +27,13 @@ class Javascript_Controller extends Controller {
// We don't need to save the session for this request
Session::abort_save();
// Dump out the javascript file
$cache = Cache::instance();
$modified = $cache->get("{$key}_modified");
if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && !empty($modified)) {
// Our data is immutable, so if they already have a copy then it needs no updating.
if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
header('HTTP/1.0 304 Not Modified');
return;
}
$content = "";
$cache = Cache::instance();
if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ) {
$content = $cache->get("{$key}_gz");
}
@@ -51,19 +48,15 @@ class Javascript_Controller extends Controller {
if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) {
header("Content-Encoding: gzip");
header("Cache-Control: private, x-gzip-ok=\"public\"");
header("Cache-Control: public");
}
header("Content-Type: text/javascript; charset=UTF-8");
header("Expires: " . gmdate(21474383647));
header("Last-Modified: " . $modified);
header("Expires: Tue, 19 Jan 2038 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s T", time()));
Kohana::close_buffers(false);
$handle = fopen("php://output", "wb");
fwrite($handle, $content);
fclose($handle);
print $content;
}
}