1 | <?php |
||
12 | class ArrayCache implements CacheInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private static $tableMapCache = []; |
||
18 | |||
19 | /** |
||
20 | * Fetches a value from the cache. |
||
21 | * |
||
22 | * @param string $key The unique key of this item in the cache. |
||
23 | * @param mixed $default Default value to return if the key does not exist. |
||
24 | * |
||
25 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
26 | * |
||
27 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
28 | * MUST be thrown if the $key string is not a legal value. |
||
29 | */ |
||
30 | 52 | public function get($key, $default = null) |
|
34 | |||
35 | /** |
||
36 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
37 | * |
||
38 | * @param string $key The key of the item to store. |
||
39 | * @param mixed $value The value of the item to store, must be serializable. |
||
40 | * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
41 | * the driver supports TTL then the library may set a default value |
||
42 | * for it or let the driver take care of that. |
||
43 | * |
||
44 | * @return bool True on success and false on failure. |
||
45 | * |
||
46 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
47 | * MUST be thrown if the $key string is not a legal value. |
||
48 | */ |
||
49 | 52 | public function set($key, $value, $ttl = null) |
|
65 | |||
66 | /** |
||
67 | * Delete an item from the cache by its unique key. |
||
68 | * |
||
69 | * @param string $key The unique cache key of the item to delete. |
||
70 | * |
||
71 | * @return bool True if the item was successfully removed. False if there was an error. |
||
72 | * |
||
73 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
74 | * MUST be thrown if the $key string is not a legal value. |
||
75 | */ |
||
76 | public function delete($key) |
||
82 | |||
83 | /** |
||
84 | * Wipes clean the entire cache's keys. |
||
85 | * |
||
86 | * @return bool True on success and false on failure. |
||
87 | */ |
||
88 | public function clear() |
||
94 | |||
95 | /** |
||
96 | * Obtains multiple cache items by their unique keys. |
||
97 | * |
||
98 | * @param iterable $keys A list of keys that can obtained in a single operation. |
||
99 | * @param mixed $default Default value to return for keys that do not exist. |
||
100 | * |
||
101 | * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
||
102 | * |
||
103 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
104 | * MUST be thrown if $keys is neither an array nor a Traversable, |
||
105 | * or if any of the $keys are not a legal value. |
||
106 | */ |
||
107 | public function getMultiple($keys, $default = null) |
||
118 | |||
119 | /** |
||
120 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
||
121 | * |
||
122 | * @param iterable $values A list of key => value pairs for a multiple-set operation. |
||
123 | * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
124 | * the driver supports TTL then the library may set a default value |
||
125 | * for it or let the driver take care of that. |
||
126 | * |
||
127 | * @return bool True on success and false on failure. |
||
128 | * |
||
129 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
130 | * MUST be thrown if $values is neither an array nor a Traversable, |
||
131 | * or if any of the $values are not a legal value. |
||
132 | */ |
||
133 | public function setMultiple($values, $ttl = null) |
||
141 | |||
142 | /** |
||
143 | * Deletes multiple cache items in a single operation. |
||
144 | * |
||
145 | * @param iterable $keys A list of string-based keys to be deleted. |
||
146 | * |
||
147 | * @return bool True if the items were successfully removed. False if there was an error. |
||
148 | * |
||
149 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
150 | * MUST be thrown if $keys is neither an array nor a Traversable, |
||
151 | * or if any of the $keys are not a legal value. |
||
152 | */ |
||
153 | public function deleteMultiple($keys) |
||
161 | |||
162 | /** |
||
163 | * Determines whether an item is present in the cache. |
||
164 | * |
||
165 | * NOTE: It is recommended that has() is only to be used for cache warming type purposes |
||
166 | * and not to be used within your live applications operations for get/set, as this method |
||
167 | * is subject to a race condition where your has() will return true and immediately after, |
||
168 | * another script can remove it making the state of your app out of date. |
||
169 | * |
||
170 | * @param string $key The cache item key. |
||
171 | * |
||
172 | * @return bool |
||
173 | * |
||
174 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
175 | * MUST be thrown if the $key string is not a legal value. |
||
176 | */ |
||
177 | 52 | public function has($key) |
|
181 | } |