1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Cache systems |
5
|
|
|
*/ |
6
|
|
|
namespace Ubiquity\cache\system; |
7
|
|
|
|
8
|
|
|
use Ubiquity\exceptions\CacheException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This class is responsible for storing Arrays in PHP files. |
12
|
|
|
* Inspired by (c) Rasmus Schultz <[email protected]> |
13
|
|
|
* <https://github.com/mindplay-dk/php-annotations> |
14
|
|
|
* Ubiquity\cache\system$AbstractDataCache |
15
|
|
|
* This class is part of Ubiquity |
16
|
|
|
* |
17
|
|
|
* @author jcheron <[email protected]> |
18
|
|
|
* @version 1.0.1 |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractDataCache { |
22
|
|
|
protected $_root; |
23
|
|
|
protected $postfix; |
24
|
|
|
|
25
|
216 |
|
public function __construct($root, $postfix = '') { |
26
|
216 |
|
$this->setRoot ( $root ); |
27
|
216 |
|
$this->postfix = $postfix; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function init() { |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Check if annotation-data for the key has been stored. |
35
|
|
|
* |
36
|
|
|
* @param string $key cache key |
37
|
|
|
* @return boolean true if data with the given key has been stored; otherwise false |
38
|
|
|
*/ |
39
|
|
|
abstract public function exists($key); |
40
|
|
|
|
41
|
|
|
public function expired($key, $duration) { |
42
|
|
|
if ($this->exists ( $key )) { |
43
|
|
|
if (\is_int ( $duration ) && $duration !== 0) { |
44
|
|
|
return \time () - $this->getTimestamp ( $key ) > $duration; |
45
|
|
|
} else { |
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
} else { |
49
|
|
|
return true; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Caches the given data with the given key. |
55
|
|
|
* |
56
|
|
|
* @param string $key cache key |
57
|
|
|
* @param mixed $code the source-code to be cached |
58
|
|
|
* @param string $tag the item tag |
59
|
|
|
* @throws CacheException |
60
|
|
|
*/ |
61
|
|
|
abstract public function store($key, $code, $tag = null); |
62
|
|
|
|
63
|
|
|
public function getRoot() { |
64
|
|
|
return $this->_root; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* |
69
|
|
|
* @param mixed $_root |
70
|
|
|
*/ |
71
|
|
|
public function setRoot($_root) { |
72
|
|
|
$this->_root = $_root; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Fetches data stored for the given key. |
77
|
|
|
* |
78
|
|
|
* @param string $key cache key |
79
|
|
|
* @return mixed the cached data |
80
|
|
|
*/ |
81
|
|
|
abstract public function fetch($key); |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* return data stored for the given key. |
85
|
|
|
* |
86
|
|
|
* @param string $key cache key |
87
|
|
|
* @return mixed the cached data |
88
|
|
|
*/ |
89
|
|
|
abstract public function file_get_contents($key); |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the timestamp of the last cache update for the given key. |
93
|
|
|
* |
94
|
|
|
* @param string $key cache key |
95
|
|
|
* @return boolean|int unix timestamp |
96
|
|
|
*/ |
97
|
|
|
abstract public function getTimestamp($key); |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* @param string $key |
102
|
|
|
*/ |
103
|
|
|
abstract public function remove($key); |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Clears all cache entries |
107
|
|
|
*/ |
108
|
|
|
abstract public function clear(); |
109
|
|
|
|
110
|
|
|
abstract public function getCacheFiles($type); |
111
|
|
|
|
112
|
|
|
abstract public function clearCache($type); |
113
|
|
|
|
114
|
3 |
|
public function getCacheInfo() { |
115
|
3 |
|
return "Cache system is an instance of <b>" . \get_class ( $this ) . "</b>."; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
abstract public function getEntryKey($key); |
119
|
|
|
} |
120
|
|
|
|