1 | <?php |
||
7 | trait AdapterTrait |
||
8 | { |
||
9 | /** |
||
10 | * Default TTL. |
||
11 | * |
||
12 | * @var int |
||
13 | */ |
||
14 | private $ttl = 0; |
||
15 | |||
16 | /** |
||
17 | * Obtains multiple cache items by their unique keys. |
||
18 | * |
||
19 | * @param iterable $keys a list of keys that can obtained in a single operation |
||
20 | * @param mixed $default default value to return for keys that do not exist |
||
21 | * |
||
22 | * @return \Generator A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
||
23 | */ |
||
24 | public function getMultiple($keys, $default = null) |
||
32 | |||
33 | /** |
||
34 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
||
35 | * |
||
36 | * @param iterable $values a list of key => value pairs for a multiple-set operation |
||
37 | * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
38 | * the driver supports TTL then the library may set a default value |
||
39 | * for it or let the driver take care of that. |
||
40 | * |
||
41 | * @return bool true on success and false on failure |
||
42 | */ |
||
43 | public function setMultiple($values, $ttl = null) |
||
56 | |||
57 | /** |
||
58 | * Deletes multiple cache items in a single operation. |
||
59 | * |
||
60 | * @param iterable $keys a list of string-based keys to be deleted |
||
61 | * |
||
62 | * @return bool True if the items were successfully removed. False if there was an error. |
||
63 | */ |
||
64 | public function deleteMultiple($keys) |
||
77 | |||
78 | /** |
||
79 | * Fetches a value from the cache. |
||
80 | * |
||
81 | * @param string $key The unique key of this item in the cache. |
||
82 | * @param mixed $default Default value to return if the key does not exist. |
||
83 | * |
||
84 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
||
85 | * |
||
86 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
87 | * MUST be thrown if the $key string is not a legal value. |
||
88 | */ |
||
89 | public abstract function get($key, $default = null); |
||
90 | |||
91 | /** |
||
92 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
||
93 | * |
||
94 | * @param string $key The key of the item to store. |
||
95 | * @param mixed $value The value of the item to store, must be serializable. |
||
96 | * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
||
97 | * the driver supports TTL then the library may set a default value |
||
98 | * for it or let the driver take care of that. |
||
99 | * |
||
100 | * @return bool True on success and false on failure. |
||
101 | * |
||
102 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
103 | * MUST be thrown if the $key string is not a legal value. |
||
104 | */ |
||
105 | public abstract function set($key, $value, $ttl = null); |
||
106 | |||
107 | /** |
||
108 | * Delete an item from the cache by its unique key. |
||
109 | * |
||
110 | * @param string $key The unique cache key of the item to delete. |
||
111 | * |
||
112 | * @return bool True if the item was successfully removed. False if there was an error. |
||
113 | * |
||
114 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
115 | * MUST be thrown if the $key string is not a legal value. |
||
116 | */ |
||
117 | public abstract function delete($key); |
||
118 | |||
119 | /** |
||
120 | * @param $key |
||
121 | * |
||
122 | * @throws InvalidArgumentException |
||
123 | */ |
||
124 | private function validateIterableKey($key) |
||
130 | |||
131 | /** |
||
132 | * @param string $key |
||
133 | * |
||
134 | * @throws InvalidArgumentException |
||
135 | */ |
||
136 | private function validateKey($key) |
||
146 | |||
147 | /** |
||
148 | * @param $ttl |
||
149 | * |
||
150 | * @return int |
||
151 | * |
||
152 | * @throws InvalidArgumentException |
||
153 | */ |
||
154 | private function getExpire($ttl) |
||
167 | } |
||
168 |