-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.php
More file actions
38 lines (32 loc) · 1 KB
/
Copy pathcache.php
File metadata and controls
38 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?PHP
/*
Taken from http://davidwalsh.name/php-cache-function
*/
class Cache{
var $CACHE_DIR = "cache/";
var $EXPIRE_TIME = 60;
var $currentTime;
function Cache(){
$this->currentTime = time();
}
//ACTUALLY CHECK IF FILE EXISTS
function exists($fileName){
echo $fileName;
return file_exists($this->CACHE_DIR . $fileName) ? ($this->currentTime - $this->EXPIRE_TIME < filemtime($this->CACHE_DIR . $fileName)) : FALSE;
}
function get($fileName){
$file_time = filemtime($this->CACHE_DIR . $fileName);
if($this->exists($fileName)) {
return file_get_contents($this->CACHE_DIR . $fileName);
}
if(exists("json_" . $fileName)) {
return json_decode(file_get_contents($this->CACHE_DIR . $fileName));
}
}
/**
* Files are cached in the cache directory, with a prefix of json_ if they need to be decoded.
**/
function setCache($fileName,$content,$isString = true){
file_put_contents($this->CACHE_DIR . ($isString ? "" : "json_") . $fileName,($isString ? $content : json_encode($content)));
}
}