-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcache.php
More file actions
62 lines (52 loc) · 1.23 KB
/
cache.php
File metadata and controls
62 lines (52 loc) · 1.23 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
53
54
55
56
57
58
59
60
61
62
<?php
/** This file is part of load.link (https://github.com/deuiore/load.link).
* View the LICENSE file for full license information.
**/
class Cache
{
protected static $cache;
public static function get()
{
if (!self::$cache)
{
self::$cache = new Cache();
}
return self::$cache;
}
protected $entities;
protected $modified;
public function __construct()
{
$this->entities = (file_exists(Path::get('cache'))) ?
unserialize(file_get_contents(Path::get('cache'))) : array();
$this->modified = FALSE;
}
public function exists($key)
{
return array_key_exists($key, $this->entities);
}
public function store($key, $value, $flush = FALSE)
{
$this->entities[$key] = $value;
$this->modified = TRUE;
if ($flush)
{
$this->flush();
}
}
public function retrieve($key)
{
if (!$this->exists($key))
{
return NULL;
}
return $this->entities[$key];
}
public function flush()
{
if ($this->modified)
{
file_put_contents(Path::get('cache'), serialize($this->entities));
}
}
}