1 | <?php |
||
41 | class LocalCacheAdapter implements CacheAdapterInterface |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * Trait that provides custom cache adapter functionality. |
||
46 | * |
||
47 | * @var TechDivision\Import\Cache\CacheAdapterTrait |
||
48 | */ |
||
49 | use CacheAdapterTrait; |
||
50 | |||
51 | /** |
||
52 | * The array with the tags. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $tags = array(); |
||
57 | |||
58 | /** |
||
59 | * The cache for the query results. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $cache = array(); |
||
64 | |||
65 | /** |
||
66 | * References that links to another cache entry. |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $references = array(); |
||
71 | |||
72 | /** |
||
73 | * The cache key utility instance. |
||
74 | * |
||
75 | * @var \TechDivision\Import\Utils\CacheKeyUtilInterface |
||
76 | */ |
||
77 | protected $cacheKeyUtil; |
||
78 | |||
79 | /** |
||
80 | * Initialize the cache handler with the passed cache and configuration instances. |
||
81 | * |
||
82 | * @param \TechDivision\Import\Utils\CacheKeyUtilInterface $cacheKeyUtil The cache key utility instance |
||
83 | */ |
||
84 | 20 | public function __construct(CacheKeyUtilInterface $cacheKeyUtil) |
|
88 | |||
89 | /** |
||
90 | * Creates a unique cache key from the passed data. |
||
91 | * |
||
92 | * @param mixed $data The date to create the cache key from |
||
93 | * |
||
94 | * @return string The generated cache key |
||
95 | */ |
||
96 | 20 | public function cacheKey($data) |
|
100 | |||
101 | /** |
||
102 | * Query whether or not a cache value for the passed cache key is available. |
||
103 | * |
||
104 | * @param string $key The cache key to query for |
||
105 | * |
||
106 | * @return boolean TRUE if the a value is available, else FALSE |
||
107 | */ |
||
108 | 20 | public function isCached($key) |
|
112 | |||
113 | /** |
||
114 | * Inversion of the isCached() method. |
||
115 | * |
||
116 | * @param string $key The cache key to query for |
||
117 | * |
||
118 | * @return boolean TRUE if the value is not available, else FALSE |
||
119 | */ |
||
120 | public function notCached($key) |
||
124 | |||
125 | /** |
||
126 | * Add's a cache reference from one key to another. |
||
127 | * |
||
128 | * @param string $from The key to reference from |
||
129 | * @param string $to The key to reference to |
||
130 | * |
||
131 | * @return void |
||
132 | */ |
||
133 | 20 | public function addReference($from, $to) |
|
137 | |||
138 | /** |
||
139 | * Resolve's the cache key. |
||
140 | * |
||
141 | * @param string $from The cache key to resolve |
||
142 | * |
||
143 | * @return string The resolved reference |
||
144 | */ |
||
145 | 20 | protected function resolveReference($from) |
|
156 | |||
157 | /** |
||
158 | * Add the passed item to the cache. |
||
159 | * |
||
160 | * @param string $key The cache key to use |
||
161 | * @param mixed $value The value that has to be cached |
||
162 | * @param array $references An array with references to add |
||
163 | * @param array $tags An array with tags to add |
||
164 | * @param boolean $override Flag that allows to override an exising cache entry |
||
165 | * @param integer $time The TTL in seconds for the passed item |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | 20 | public function toCache($key, $value, array $references = array(), array $tags = array(), $override = false, $time = null) |
|
200 | |||
201 | /** |
||
202 | * Returns a new cache item for the passed key |
||
203 | * |
||
204 | * @param string $key The cache key to return the item for |
||
205 | * |
||
206 | * @return mixed The value for the passed key |
||
207 | */ |
||
208 | public function fromCache($key) |
||
214 | |||
215 | /** |
||
216 | * Flush the cache and remove the references. |
||
217 | * |
||
218 | * @return void |
||
219 | */ |
||
220 | public function flushCache() |
||
226 | |||
227 | /** |
||
228 | * Invalidate the cache entries for the passed tags. |
||
229 | * |
||
230 | * @param array $tags The tags to invalidate the cache for |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | public function invalidateTags(array $tags) |
||
258 | |||
259 | /** |
||
260 | * Remove the item with the passed key and all its references from the cache. |
||
261 | * |
||
262 | * @param string $key The key of the cache item to Remove |
||
263 | * |
||
264 | * @return void |
||
265 | */ |
||
266 | 10 | public function removeCache($key) |
|
270 | } |
||
271 |