comparison 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
comparison
equal deleted inserted replaced
37:da1726860524 38:42533600214b
1 <?php
2 class CacheTimeCheck
3 {
4 private $newest;
5 private $files = array();
6
7 function __construct($minTime = 0, $filename = False)
8 {
9 if ($filename)
10 array_push($this->files, $filename);
11 $this->newest = $minTime;
12 $this->cache_time(__FILE__);
13 }
14
15 function CheckHttpModified()
16 {
17 if (DEBUG)
18 var_dump($_SERVER);
19
20 $HTTP_IF_MODIFIED_SINCE=$_SERVER['HTTP_IF_MODIFIED_SINCE'];
21 $if_modified_since = preg_replace('/;.*$/', '', $HTTP_IF_MODIFIED_SINCE);
22
23 $gmdate_mod = gmdate('D, d M Y H:i:s', $this->newest) . ' GMT';
24
25 if ($if_modified_since == $gmdate_mod) {
26 header("HTTP/1.0 304 Not Modified");
27 exit;
28 }
29 header("Last-Modified: $gmdate_mod");
30 }
31
32 function cache_time($path)
33 {
34 array_push($this->files, $path);
35 $mtime = filemtime($path);
36 if ($mtime > $this->newest) {
37 $this->newest = $mtime;
38 }
39 }
40
41 function includeOnce($path)
42 {
43 $this->cache_time($path);
44 include_once($path);
45 }
46
47 function loadFile($path)
48 {
49 $this->cache_time($path);
50 return loadFile($path);
51 }
52 }
53 ?>