1 | <?php |
||
19 | class Cache |
||
20 | { |
||
21 | /** |
||
22 | * @var resource |
||
23 | */ |
||
24 | protected $dba; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $handler; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $storage; |
||
35 | |||
36 | /** |
||
37 | * @param string $file the cache-file. |
||
38 | * |
||
39 | * @param string $handler the dba handler. |
||
40 | * |
||
41 | * You have to install one of this handlers before use. |
||
42 | * |
||
43 | * cdb = Tiny Constant Database - for reading. |
||
44 | * cdb_make = Tiny Constant Database - for writing. |
||
45 | * db4 = Oracle Berkeley DB 4 - for reading and writing. |
||
46 | * qdbm = Quick Database Manager - for reading and writing. |
||
47 | * gdbm = GNU Database Manager - for reading and writing. |
||
48 | * inifile = Ini File - for reading and writing. |
||
49 | * flatfile = default dba extension - for reading and writing. |
||
50 | * |
||
51 | * Use "flatfile" only when you cannot install one, of the libraries |
||
52 | * required by the other handlers, and when you cannot use bundled cdb handler. |
||
53 | * |
||
54 | * @param string $mode For read/write access, database creation if it doesn't currently exist. |
||
55 | * |
||
56 | * r = for read access |
||
57 | * w = for read/write access to an already existing database |
||
58 | * c = for read/write access and database creation if it doesn't currently exist |
||
59 | * n = for create, truncate and read/write access |
||
60 | * |
||
61 | * When you are absolutely sure that you do not require database locking you can use "-" as suffix. |
||
62 | * |
||
63 | * @param boolean $persistently |
||
64 | * |
||
65 | * @throws \RuntimeException If no DBA extension or handler installed. |
||
66 | */ |
||
67 | public function __construct($file, $handler = 'flatfile', $mode = 'c', $persistently = true) |
||
89 | |||
90 | /** |
||
91 | * Closes an open dba resource |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | public function __destruct() |
||
99 | |||
100 | /** |
||
101 | * @param string $key |
||
102 | * @param mixed $value |
||
103 | * @param int|bool $ltime Lifetime in seconds otherwise cache forever. |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function put($key, $value, $ltime = false) |
||
121 | |||
122 | /** |
||
123 | * @param string $key |
||
124 | * @param mixed $value |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function forever($key, $value) |
||
132 | |||
133 | /** |
||
134 | * @param string $key |
||
135 | * |
||
136 | * @return bool|object |
||
137 | */ |
||
138 | public function get($key) |
||
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | */ |
||
158 | public function getStorage() |
||
162 | |||
163 | /** |
||
164 | * @param string $key |
||
165 | * |
||
166 | * @return Capsule|boolean |
||
167 | */ |
||
168 | public function fetch($key) |
||
182 | |||
183 | /** |
||
184 | * @param string $key |
||
185 | * |
||
186 | * @return boolean |
||
187 | */ |
||
188 | public function delete($key) |
||
200 | |||
201 | /** |
||
202 | * @param string $key |
||
203 | * |
||
204 | * @return boolean |
||
205 | */ |
||
206 | public function has($key) |
||
210 | |||
211 | /** |
||
212 | * Close the handler. |
||
213 | */ |
||
214 | public function closeDba() |
||
221 | |||
222 | /** |
||
223 | * @return resource |
||
224 | */ |
||
225 | public function getDba() |
||
229 | |||
230 | /** |
||
231 | * @return \ArrayObject of stored cache ids (string). |
||
232 | */ |
||
233 | public function getIds() |
||
246 | |||
247 | /** |
||
248 | * Return an array of metadata for the given cache id. |
||
249 | * |
||
250 | * - expire = the expire timestamp |
||
251 | * - mtime = timestamp of last modification time |
||
252 | * |
||
253 | * @param string $key cache id |
||
254 | * |
||
255 | * @return array|boolean |
||
256 | */ |
||
257 | public function getMetaData($key) |
||
270 | |||
271 | /** |
||
272 | * Ensures if a single cache-item can be deleted. |
||
273 | * |
||
274 | * @param null|string $handler |
||
275 | * |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function erasable($handler = null) |
||
284 | } |
||
285 |