diff CacheTimeCheck.inc @ 38:42533600214b

Rename cache_check.inc to CacheTimeCheck.inc. Proper caching in flag.php.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 04 Oct 2012 22:07:19 +0200
parents cache_check.inc@7b19be62ea94
children bd82b719a0de
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CacheTimeCheck.inc	Thu Oct 04 22:07:19 2012 +0200
@@ -0,0 +1,53 @@
+<?php
+class CacheTimeCheck
+{
+  private $newest;
+  private $files = array();
+
+  function __construct($minTime = 0, $filename = False)
+  {
+    if ($filename)
+      array_push($this->files, $filename);
+    $this->newest = $minTime;
+    $this->cache_time(__FILE__);
+  }
+
+  function CheckHttpModified()
+  {
+    if (DEBUG)
+      var_dump($_SERVER);
+
+    $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
+    $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
+
+    $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT';
+
+    if ($if_modified_since == $gmdate_mod) {
+      header("HTTP/1.0 304 Not Modified");
+      exit;
+    }
+    header("Last-Modified: $gmdate_mod");
+  }
+
+  function cache_time($path)
+  {
+    array_push($this->files, $path);
+    $mtime = filemtime($path);
+    if ($mtime > $this->newest) {
+      $this->newest = $mtime;
+    }
+  }
+
+  function includeOnce($path)
+  {
+    $this->cache_time($path);
+    include_once($path);
+  }
+
+  function loadFile($path)
+  {
+    $this->cache_time($path);
+    return loadFile($path);
+  }
+}
+?>
\ No newline at end of file