1 | <?php |
||
31 | class SQLite3Cache extends CacheProvider |
||
32 | { |
||
33 | /** |
||
34 | * The ID field will store the cache key. |
||
35 | */ |
||
36 | const ID_FIELD = 'k'; |
||
37 | |||
38 | /** |
||
39 | * The data field will store the serialized PHP value. |
||
40 | */ |
||
41 | const DATA_FIELD = 'd'; |
||
42 | |||
43 | /** |
||
44 | * The expiration field will store a date value indicating when the |
||
45 | * cache entry should expire. |
||
46 | */ |
||
47 | const EXPIRATION_FIELD = 'e'; |
||
48 | |||
49 | /** |
||
50 | * @var SQLite3 |
||
51 | */ |
||
52 | private $sqlite; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $table; |
||
58 | |||
59 | /** |
||
60 | * Constructor. |
||
61 | * |
||
62 | * Calling the constructor will ensure that the database file and table |
||
63 | * exist and will create both if they don't. |
||
64 | * |
||
65 | * @param SQLite3 $sqlite |
||
66 | * @param string $table |
||
67 | */ |
||
68 | public function __construct(SQLite3 $sqlite, $table) |
||
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | protected function doFetch($id) |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | protected function doContains($id) |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | protected function doSave($id, $data, $lifeTime = 0) |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | protected function doDelete($id) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | protected function doFlush() |
||
149 | |||
150 | /** |
||
151 | * {@inheritdoc} |
||
152 | */ |
||
153 | protected function doGetStats() |
||
157 | |||
158 | /** |
||
159 | * Find a single row by ID. |
||
160 | * |
||
161 | * @param mixed $id |
||
162 | * @param bool $includeData |
||
163 | * |
||
164 | * @return array|null |
||
165 | */ |
||
166 | private function findById($id, $includeData = true) |
||
198 | |||
199 | /** |
||
200 | * Gets an array of the fields in our table. |
||
201 | * |
||
202 | * @return array |
||
203 | */ |
||
204 | private function getFields() |
||
208 | |||
209 | /** |
||
210 | * Check if the item is expired. |
||
211 | * |
||
212 | * @param array $item |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | private function isExpired(array $item) |
||
222 | } |
||
223 |