1 | <?php |
||
23 | class Cache{ |
||
24 | |||
25 | /** |
||
26 | * Underlying Cache object |
||
27 | * @var CacheItemPoolInterface $cache |
||
28 | */ |
||
29 | protected $cache=null; |
||
30 | |||
31 | /** |
||
32 | * Defines whether the cache has been initialised |
||
33 | * @var bool $is_init |
||
34 | */ |
||
35 | protected $is_init = false; |
||
36 | |||
37 | /** |
||
38 | * *Cache* instance for Singleton pattern |
||
39 | * @var Cache $instance |
||
40 | */ |
||
41 | protected static $instance = null; |
||
42 | |||
43 | /** |
||
44 | * Returns the *Cache* instance of this class. |
||
45 | * |
||
46 | * @return Cache The *Singleton* instance. |
||
47 | */ |
||
48 | protected static function getInstance() |
||
56 | |||
57 | /** |
||
58 | * Initialise the Cache class |
||
59 | * |
||
60 | */ |
||
61 | protected function init() { |
||
81 | |||
82 | /** |
||
83 | * Initiliase the Cache if not done. |
||
84 | * |
||
85 | */ |
||
86 | protected function checkInit(){ |
||
89 | |||
90 | /** |
||
91 | * Returns the name of the cached key, based on the value name and the calling module |
||
92 | * |
||
93 | * @param string $value Value name |
||
94 | * @param AbstractModule $mod Calling module |
||
95 | * @return string Cached key name |
||
96 | */ |
||
97 | protected function getKeyName($value, AbstractModule $mod = null){ |
||
103 | |||
104 | /** |
||
105 | * Returns the cached value, if exists |
||
106 | * |
||
107 | * @param string $value Value name |
||
108 | * @param AbstractModule $mod Calling module |
||
109 | * @return \Psr\Cache\CacheItemInterface |
||
110 | */ |
||
111 | public function getI($value, AbstractModule $mod = null){ |
||
115 | |||
116 | /** |
||
117 | * Static invocation of the *get* method. |
||
118 | * |
||
119 | * @param string $value Value name |
||
120 | * @param AbstractModule $mod Calling module |
||
121 | * @return \Psr\Cache\CacheItemInterface |
||
122 | */ |
||
123 | public static function get($value, AbstractModule $mod = null){ |
||
126 | |||
127 | /** |
||
128 | * Cache a value to the specified key |
||
129 | * |
||
130 | * @param string|\Psr\Cache\CacheItemInterface $value Value name |
||
131 | * @param mixed $data Value |
||
132 | * @param AbstractModule $mod Calling module |
||
133 | */ |
||
134 | public function saveI($value, $data, AbstractModule $mod = null){ |
||
145 | |||
146 | /** |
||
147 | * Static invocation of the *save* method. |
||
148 | * |
||
149 | * @param string|\Psr\Cache\CacheItemInterface $value Value name |
||
150 | * @param mixed $data Value |
||
151 | * @param AbstractModule $mod Calling module |
||
152 | */ |
||
153 | public static function save($value, $data, AbstractModule $mod = null){ |
||
156 | |||
157 | /** |
||
158 | * Delete the value associated to the specified key |
||
159 | * |
||
160 | * @param string $value Value name |
||
161 | * @param AbstractModule $mod Calling module |
||
162 | * @return bool Deletion successful? |
||
163 | */ |
||
164 | public function deleteI($value, AbstractModule $mod = null){ |
||
168 | |||
169 | /** |
||
170 | * Static invocation of the *delete* method. |
||
171 | * |
||
172 | * @param string $value Value name |
||
173 | * @param AbstractModule $mod Calling module |
||
174 | * @return bool Deletion successful? |
||
175 | */ |
||
176 | public static function delete($value, AbstractModule $mod = null){ |
||
179 | |||
180 | /** |
||
181 | * Clean the cache |
||
182 | * |
||
183 | */ |
||
184 | public function cleanI(){ |
||
188 | |||
189 | /** |
||
190 | * Static invocation of the *clean* method. |
||
191 | */ |
||
192 | public static function clean() { |
||
195 | |||
196 | } |
If you suppress an error, we recommend checking for the error condition explicitly: