1 | <?php |
||
34 | class GenericCacheAdapter implements CacheAdapterInterface |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * The cache for the query results. |
||
39 | * |
||
40 | * @var \Psr\Cache\CacheItemPoolInterface |
||
41 | */ |
||
42 | protected $cache; |
||
43 | |||
44 | /** |
||
45 | * References that links to another cache entry. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $references = array(); |
||
50 | |||
51 | /** |
||
52 | * Initialize the cache handler with the passed cache and configuration instances. |
||
53 | * . |
||
54 | * @param \Psr\Cache\CacheItemPoolInterface $cache The cache instance |
||
55 | */ |
||
56 | public function __construct(CacheItemPoolInterface $cache) |
||
60 | |||
61 | /** |
||
62 | * Prepares a unique cache key for the passed query name and params. |
||
63 | * |
||
64 | * @param string $uniqueName A unique name used to prepare the cache key with |
||
65 | * @param array $params The query params |
||
66 | * |
||
67 | * @return string The prepared cache key |
||
68 | */ |
||
69 | public function cacheKey($uniqueName, array $params) |
||
73 | |||
74 | /** |
||
75 | * Query whether or not a cache value for the passed cache key is available. |
||
76 | * |
||
77 | * @param string $key The cache key to query for |
||
78 | * |
||
79 | * @return boolean TRUE if the a value is available, else FALSE |
||
80 | */ |
||
81 | public function isCached($key) |
||
92 | |||
93 | /** |
||
94 | * Inversion of the isCached() method. |
||
95 | * |
||
96 | * @param string $cacheKey The cache key to query for |
||
97 | * |
||
98 | * @return boolean TRUE if the value is not available, else FALSE |
||
99 | */ |
||
100 | public function notCached($key) |
||
104 | |||
105 | /** |
||
106 | * Add's a cache reference from one key to another. |
||
107 | * |
||
108 | * @param string $from The key to reference from |
||
109 | * @param string $to The key to reference to |
||
110 | * |
||
111 | * @return void |
||
112 | */ |
||
113 | public function addReference($from, $to) |
||
117 | |||
118 | /** |
||
119 | * Resolve's the cache key. |
||
120 | * |
||
121 | * @param string $from The cache key to resolve |
||
122 | * |
||
123 | * @return string The resolved reference |
||
124 | */ |
||
125 | protected function resolveReference($from) |
||
136 | |||
137 | /** |
||
138 | * Add the passed item to the cache. |
||
139 | * |
||
140 | * @param string $key The cache key to use |
||
141 | * @param mixed $value The value that has to be cached |
||
142 | * @param array $references An array with references to add |
||
143 | * @param boolean $override Flag that allows to override an exising cache entry |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | public function toCache($key, $value, array $references = array(), $override = false) |
||
167 | |||
168 | /** |
||
169 | * Returns a new cache item for the passed key |
||
170 | * |
||
171 | * @param string $key The cache key to return the item for |
||
172 | * |
||
173 | * @return mixed The value for the passed key |
||
174 | */ |
||
175 | public function fromCache($key) |
||
179 | |||
180 | /** |
||
181 | * Flush the cache, or the value with the passed key. |
||
182 | * |
||
183 | * @param mixed|null $key The key of the value to flush |
||
184 | * |
||
185 | * @return void |
||
186 | */ |
||
187 | public function flushCache($key = null) |
||
201 | |||
202 | /** |
||
203 | * Raises the value for the attribute with the passed key by one. |
||
204 | * |
||
205 | * @param mixed $key The key of the attribute to raise the value for |
||
206 | * @param mixed $counterName The name of the counter to raise |
||
207 | * |
||
208 | * @return integer The counter's new value |
||
209 | */ |
||
210 | public function raiseCounter($key, $counterName) |
||
228 | |||
229 | /** |
||
230 | * This method merges the passed attributes with an array that |
||
231 | * has already been added under the passed key. |
||
232 | * |
||
233 | * If no value will be found under the passed key, the attributes |
||
234 | * will simply be registered. |
||
235 | * |
||
236 | * @param mixed $key The key of the attributes that has to be merged with the passed ones |
||
237 | * @param array $attributes The attributes that has to be merged with the exising ones |
||
238 | * |
||
239 | * @return void |
||
240 | * @throws \Exception Is thrown, if the already registered value is no array |
||
241 | * @link http://php.net/array_replace_recursive |
||
242 | */ |
||
243 | public function mergeAttributesRecursive($key, array $attributes) |
||
261 | } |
||
262 |