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 | 78 | public function __construct(SQLite3 $sqlite, $table) |
|
75 | |||
76 | 78 | private function ensureTableExists() : void |
|
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 76 | protected function doFetch($id) |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 73 | protected function doContains($id) |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 74 | protected function doSave($id, $data, $lifeTime = 0) |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | 46 | protected function doDelete($id) |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 2 | protected function doFlush() |
|
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | 1 | protected function doGetStats() |
|
162 | |||
163 | /** |
||
164 | * Find a single row by ID. |
||
165 | * |
||
166 | * @param mixed $id |
||
167 | * @param bool $includeData |
||
168 | * |
||
169 | * @return array|null |
||
170 | */ |
||
171 | 76 | private function findById($id, bool $includeData = true) : ?array |
|
203 | |||
204 | /** |
||
205 | * Gets an array of the fields in our table. |
||
206 | * |
||
207 | * @return array |
||
208 | */ |
||
209 | 76 | private function getFields() : array |
|
213 | |||
214 | /** |
||
215 | * Check if the item is expired. |
||
216 | * |
||
217 | * @param array $item |
||
218 | * |
||
219 | * @return bool |
||
220 | */ |
||
221 | 70 | private function isExpired(array $item) : bool |
|
227 | } |
||
228 |