-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsimpleCache.php
More file actions
52 lines (37 loc) · 1.03 KB
/
simpleCache.php
File metadata and controls
52 lines (37 loc) · 1.03 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class SimpleCache {
// Properties
public $name;
// Methods
function setName($name) {
$this->name = $name;
}
function getName() {
return $this->name;
}
function setCache($name,$content) {
try {
$cachefile = (dirname(__FILE__) .'/cached-files/'.$name.'.php');
$fp = fopen($cachefile, 'w');
if ($fp === false) {
throw new Exception("Please set write permissions on the /cached-files folder<br/>");
}
fwrite($fp, json_encode($content));
fclose($fp);
} catch (Exception $e) {
// Handle the exception
echo 'Error: ' . $e->getMessage();
}
}
function getCache($name) {
$cachefile = (dirname(__FILE__) .'/cached-files/'.$name.'.php');
if (file_exists($cachefile)) {
$fp = fopen($cachefile, 'r');
$fileContents = fread($fp,filesize($cachefile));
fclose($fp);
return json_decode($fileContents);
}
return null;
}
}
?>