1 | <?php |
||
22 | class Cache |
||
23 | { |
||
24 | /** |
||
25 | * Cache backend |
||
26 | * |
||
27 | * @var Adapter |
||
28 | **/ |
||
29 | private $backend; |
||
30 | |||
31 | /** |
||
32 | * Default life time |
||
33 | * |
||
34 | * @var int |
||
35 | **/ |
||
36 | private $defaultLifeTime = 3600; |
||
37 | |||
38 | /** |
||
39 | * Cache id prefix |
||
40 | * |
||
41 | * @var string |
||
42 | **/ |
||
43 | private $idPrefix = ''; |
||
44 | |||
45 | /** |
||
46 | * Constructor |
||
47 | * |
||
48 | * @return void |
||
|
|||
49 | **/ |
||
50 | public function __construct(Adapter $backend) |
||
54 | |||
55 | /** |
||
56 | * Save something in the cache |
||
57 | * |
||
58 | * @param mixed $data |
||
59 | * @param string $id |
||
60 | * @param int $lifeTime |
||
61 | * @access public |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function save($data, $id, $lifeTime = -1) |
||
72 | |||
73 | /** |
||
74 | * Load something from the cache |
||
75 | * |
||
76 | * @param string $id |
||
77 | * @return mixed|ResultNotFound |
||
78 | **/ |
||
79 | public function load($id) |
||
91 | |||
92 | /** |
||
93 | * Remove something from the cache |
||
94 | * |
||
95 | * @param string $id |
||
96 | * @return bool |
||
97 | **/ |
||
98 | public function delete($id) |
||
104 | |||
105 | /** |
||
106 | * Create a cache key based on a variable number of inputs |
||
107 | * |
||
108 | * This method accepts alpha numeric strings, but also serializable objects. |
||
109 | * All of these will be concatenated into a single id string. |
||
110 | * |
||
111 | * @param mixed $keyPart1 |
||
112 | * @param mixed $keyPart2 |
||
113 | * ... |
||
114 | * @param mixed $keyPartN |
||
115 | * @return string |
||
116 | **/ |
||
117 | public static function key() |
||
158 | |||
159 | /** |
||
160 | * Get the default life time |
||
161 | * |
||
162 | * @return int |
||
163 | */ |
||
164 | public function getDefaultLifeTime() |
||
168 | |||
169 | /** |
||
170 | * Set the default life time |
||
171 | * |
||
172 | * @param int $defaultLifeTime |
||
173 | * @return Cache |
||
174 | */ |
||
175 | public function setDefaultLifeTime($defaultLifeTime) |
||
181 | |||
182 | /** |
||
183 | * Get the cache id prefix |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getIdPrefix() |
||
191 | |||
192 | /** |
||
193 | * Set the cache id prefix |
||
194 | * |
||
195 | * @param string $prefix |
||
196 | * @return Cache |
||
197 | */ |
||
198 | public function setIdPrefix($prefix) |
||
204 | |||
205 | /** |
||
206 | * Add an id prefix |
||
207 | * |
||
208 | * @param string $prefix |
||
209 | * @return Cache |
||
210 | **/ |
||
211 | public function addIdPrefix($prefix) |
||
217 | |||
218 | /** |
||
219 | * Get the cache backend adapter |
||
220 | * |
||
221 | * @return Adapter |
||
222 | */ |
||
223 | public function getBackend() |
||
227 | |||
228 | /** |
||
229 | * Set the cache backend adapter |
||
230 | * |
||
231 | * @param Adapter $backend |
||
232 | * @return Cache |
||
233 | */ |
||
234 | public function setBackend(Adapter $backend) |
||
240 | |||
241 | /** |
||
242 | * Get the full, prefixed id |
||
243 | * |
||
244 | * @see setIdPrefix() |
||
245 | * |
||
246 | * @param string $id |
||
247 | * @return string |
||
248 | */ |
||
249 | private function getIdPrefixed($id) |
||
257 | |||
258 | /** |
||
259 | * Get the life time to use |
||
260 | * |
||
261 | * Will return default life time if $lifeTime < 0 |
||
262 | * |
||
263 | * @see setDefaultLifeTime() |
||
264 | * |
||
265 | * @param int $lifeTime |
||
266 | * @return int |
||
267 | **/ |
||
268 | private function getLifeTime($lifeTime) |
||
276 | |||
277 | /** |
||
278 | * Serialize some data into string form |
||
279 | * |
||
280 | * @param mixed $data |
||
281 | * @return string |
||
282 | **/ |
||
283 | private function serialize($data) |
||
287 | |||
288 | /** |
||
289 | * Unserialize some data |
||
290 | * |
||
291 | * @param string $data |
||
292 | * @return mixed |
||
293 | **/ |
||
294 | private function unserialize($data) |
||
298 | } |
||
299 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.