1 | <?php |
||
20 | class CacheService |
||
21 | { |
||
22 | /** |
||
23 | * Prefix to use for the tag key |
||
24 | * @var string |
||
25 | */ |
||
26 | const TAG_PREFIX = 'strokercache_'; |
||
27 | |||
28 | /** |
||
29 | * @var EventManagerInterface |
||
30 | */ |
||
31 | protected $eventManager; |
||
32 | |||
33 | /** |
||
34 | * @var StorageInterface |
||
35 | */ |
||
36 | protected $cacheStorage; |
||
37 | |||
38 | /** |
||
39 | * @var IdGeneratorInterface |
||
40 | */ |
||
41 | protected $idGenerator; |
||
42 | |||
43 | /** |
||
44 | * @var ModuleOptions |
||
45 | */ |
||
46 | protected $options; |
||
47 | |||
48 | /** |
||
49 | * Default constructor |
||
50 | * |
||
51 | * @param StorageInterface $cacheStorage |
||
52 | * @param ModuleOptions $options |
||
53 | * @param IdGeneratorInterface $idGenerator |
||
54 | */ |
||
55 | public function __construct(StorageInterface $cacheStorage, ModuleOptions $options, IdGeneratorInterface $idGenerator = null) |
||
61 | |||
62 | /** |
||
63 | * Check if a page is saved in the cache and return contents. Return null when no item is found. |
||
64 | * |
||
65 | * @param MvcEvent $mvcEvent |
||
66 | * @return mixed|null |
||
67 | */ |
||
68 | public function load(MvcEvent $mvcEvent) |
||
87 | |||
88 | /** |
||
89 | * Save the page contents to the cache storage. |
||
90 | * |
||
91 | * @param MvcEvent $mvcEvent |
||
92 | */ |
||
93 | public function save(MvcEvent $mvcEvent) |
||
117 | |||
118 | /** |
||
119 | * Determine if we should cache the current request |
||
120 | * |
||
121 | * @param MvcEvent $mvcEvent |
||
122 | * @return bool |
||
123 | */ |
||
124 | protected function shouldCacheRequest(MvcEvent $mvcEvent) |
||
138 | |||
139 | /** |
||
140 | * @param array $tags |
||
141 | * @param bool|null $disjunction |
||
142 | * @return bool |
||
143 | * @throws UnsupportedAdapterException |
||
144 | */ |
||
145 | public function clearByTags(array $tags = array(), $disjunction = null) |
||
158 | |||
159 | /** |
||
160 | * Cache tags to use for this page |
||
161 | * |
||
162 | * @param MvcEvent $event |
||
163 | * @return array |
||
164 | */ |
||
165 | public function getTags(MvcEvent $event) |
||
181 | |||
182 | /** |
||
183 | * @param string $eventName |
||
184 | * @param string $cacheKey |
||
185 | * @param MvcEvent|null $mvcEvent |
||
186 | * @return CacheEvent |
||
187 | */ |
||
188 | protected function createCacheEvent($eventName, MvcEvent $mvcEvent = null, $cacheKey = null) |
||
198 | |||
199 | /** |
||
200 | * @return StorageInterface |
||
201 | */ |
||
202 | public function getCacheStorage() |
||
206 | |||
207 | /** |
||
208 | * @param StorageInterface $cacheStorage |
||
209 | * @return self |
||
210 | */ |
||
211 | public function setCacheStorage($cacheStorage) |
||
217 | |||
218 | /** |
||
219 | * @return ModuleOptions |
||
220 | */ |
||
221 | public function getOptions() |
||
225 | |||
226 | /** |
||
227 | * @param ModuleOptions $options |
||
228 | * @return self |
||
229 | */ |
||
230 | public function setOptions($options) |
||
236 | |||
237 | /** |
||
238 | * Inject an EventManager instance |
||
239 | * |
||
240 | * @param EventManagerInterface $eventManager |
||
241 | * @return self |
||
242 | */ |
||
243 | public function setEventManager(EventManagerInterface $eventManager) |
||
251 | |||
252 | /** |
||
253 | * Retrieve the event manager |
||
254 | * |
||
255 | * Lazy-loads an EventManager instance if none registered. |
||
256 | * |
||
257 | * @return EventManagerInterface |
||
258 | */ |
||
259 | public function getEventManager() |
||
267 | |||
268 | /** |
||
269 | * @return IdGeneratorInterface |
||
270 | */ |
||
271 | public function getIdGenerator() |
||
275 | |||
276 | /** |
||
277 | * @param IdGeneratorInterface $idGenerator |
||
278 | */ |
||
279 | public function setIdGenerator($idGenerator = null) |
||
283 | } |
||
284 |