Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 59 lines (42 sloc) 1.278 kb
9e837d3 Harris Novick Implemented PHP caching of articles. Improving #reader styles.
authored
1 <?php
2
3 class SimpleCache
4 {
5 private $expiryInterval = 604800;
6
7 public function put($domain, $key, $content)
8 {
4cdb06d Harris Novick Edits
authored
9 $myCacheDir = 'cache/' . $domain[0] . '/' . $domain;
9e837d3 Harris Novick Implemented PHP caching of articles. Improving #reader styles.
authored
10
11 if (! file_exists($myCacheDir))
12 mkdir($myCacheDir);
13
14 $filename_cache = $myCacheDir . '/' . $key . '.cache'; //Cache filename
15
16 file_put_contents ($filename_cache , $content); // save the content
17 }
18
19 public function get($domain, $key)
20 {
4cdb06d Harris Novick Edits
authored
21 $myCacheDir = 'cache/' . $domain[0] . '/' . $domain;
9e837d3 Harris Novick Implemented PHP caching of articles. Improving #reader styles.
authored
22
23 $filename_cache = $myCacheDir . '/' . $key . '.cache'; //Cache filename
24
25 if (file_exists($filename_cache))
26 {
27 $cache_time = strtotime(filemtime($filename_cache)) - (int)$expiryInterval;
28
29 if ((int)$cache_time >= 0) //Compare last updated and current time
30 {
31 return file_get_contents ($filename_cache); //Get contents from file
32 }
33 }
34
35 return null;
36 }
37
38 public function exists($domain, $key)
39 {
4cdb06d Harris Novick Edits
authored
40 $myCacheDir = 'cache/' . $domain[0] . '/' . $domain;
9e837d3 Harris Novick Implemented PHP caching of articles. Improving #reader styles.
authored
41
42 $filename_cache = $myCacheDir . '/' . $key . '.cache'; //Cache filename
43
44 if (file_exists($filename_cache))
45 {
46 $cache_time = strtotime(filemtime($filename_cache)) - (int)$expiryInterval;
47
48 if ((int)$cache_time >= 0) //Compare last updated and current time
49 {
50 return true;
51 }
52 }
53
54 return false;
55 }
56
57 }
58
59 ?>
Something went wrong with that request. Please try again.