From c3e297e08ff1e1a60617e64bf3eace8db07c18f8 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Fri, 26 Sep 2014 16:50:45 +0200 Subject: trigger short expire if files recently updated (may not yet be up to date on other slaves) --- itjs.class | 5 ++++- itjs.php | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/itjs.class b/itjs.class index c8fe29b..f73698d 100644 --- a/itjs.class +++ b/itjs.class @@ -191,7 +191,10 @@ static function checksum($fnlist) $filenames = array_merge(is_array($fnlist) ? $fnlist : itjs::filenames($fnlist), array("/www/lib.search.ch/var/jquery-ui/dist/minified/jquery.ui.core.min.js", "/www/lib.search.ch/var/jquery/dist/jquery.min.js")); # jquery files included by lib/jquery.js $key = "itjs_" . md5(join("", it::map('"$v" . @filemtime("$v")', $filenames))); - return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents($filenames, false)), 0, 10), array('ttl' => 60)); + if (time() - max(array_map('filemtime', $filenames)) < 60) + return "-"; # trigger short expire, our file may not yet be up to date on other slaves + else + return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents($filenames, false)), 0, 10), array('ttl' => 60)); } function crcurl($url) diff --git a/itjs.php b/itjs.php index 4bcacbe..62cd474 100644 --- a/itjs.php +++ b/itjs.php @@ -24,7 +24,8 @@ require "itools/itools.lib"; if (EDC('slow' . it::match('\.(\w+)$', $_SERVER['PHP_SELF']))) sleep(10); -if (false && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) +$crc = $_REQUEST['c'] ?: $_REQUEST['s']; +if (false && $crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) { header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has exit; @@ -71,7 +72,7 @@ else if (!it::match('\.html$', $file)) if (it::is_live() && !$_REQUEST['retry']) { - $keeptime = /* $_REQUEST['s'] || $_REQUEST['c'] ? 86400*30 : */ 900; # long expire if checksum present DISABLED + $keeptime = $crc == "-" ? 0 : ($crc ? 900 : 900); # long expire if checksum present DISABLED header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT"); } -- cgit v1.2.3