summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues@hiegel.fr>2010-10-07 16:21:36 +0200
committerHugues Hiegel <hugues@hiegel.fr>2010-10-07 16:21:36 +0200
commitc6d81aa4a0cb01f17163523c63ea0a0dd4eefae8 (patch)
treea5181337806bb49d045702d1fb5a7693a2377e58
parentf8b7d9bd145d1d8026c9316f432076498e7ac6fa (diff)
Cache: better cache managment ?
-rw-r--r--BigLine.php40
1 files changed, 34 insertions, 6 deletions
diff --git a/BigLine.php b/BigLine.php
index 9a0ef5f..4e5c65a 100644
--- a/BigLine.php
+++ b/BigLine.php
@@ -59,11 +59,19 @@ OR ($data["lastupdate"] AND $data["lastupdate"]+CACHE < time()))
/*output image cache*/
$Cache=CACHE_FOLDER."/Pictures/".strtolower(rawurlencode($username))."_$type-$style-$color.png";
-clearstatcache();
+//clearstatcache();
-//if (is_file($Cache) AND (filemtime($Cache) >= $data['lastupdate'])){
- //header("Location: ".$Cache); //its faster, but you should set CACHE_FOLDER = "."
-//}
+/*
+if (is_file($Cache) AND (filemtime($Cache) >= $data['lastupdate'])){
+ header("Location: /~hugues/Last.fm/".$Cache); //its faster, but you should set CACHE_FOLDER = "."
+ exit;
+}
+*/
+
+if (is_file($Cache))
+{
+ SendCacheHeaders(filemtime($Cache), CACHE);
+}
/*-----------------------------------------------------------
Ok, now we are ready to create the image with GD.
@@ -92,7 +100,7 @@ else
if ( !is_file($Cache)
OR (filemtime($Cache) < $data['lastupdate'])
OR !filesize($Cache)
- OR $username == "gugusse")
+ )
{
$duration = $_SERVER['REQUEST_TIME'] - $statsstart;
@@ -220,11 +228,31 @@ else
{
touch_badge($username, $type, $style, $color);
header("Content-Type: image/png");
- //echo $Cache;
echo file_get_contents($Cache);
}
}
+function GetGMT($time)
+{
+ return gmdate("D, d M Y H:i:s", $time) . " GMT";
+}
+
+function SendCacheHeaders($lastmodified, $maxage, $limit="public")
+{
+ $LastModified = GetGMT($lastmodified);
+ if ("$_SERVER[HTTP_IF_MODIFIED_SINCE]" == "$LastModified")
+ {
+ header("HTTP/1.1 304 Not Modified");
+ exit;
+ }
+
+ /* Give a fresh copy */
+ $Expires = GetGMT($lastmodified + $maxage);
+ header("Cache-Control: max-age=$maxage, $limit");
+ header("Last-Modified: $LastModified");
+ header("Expires: $Expires");
+}
+
function make_db_cache($username){