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) |
||
88 | |||
89 | /** |
||
90 | * Save the page contents to the cache storage. |
||
91 | * |
||
92 | * @param MvcEvent $mvcEvent |
||
93 | */ |
||
94 | public function save(MvcEvent $mvcEvent) |
||
116 | |||
117 | /** |
||
118 | * Determine if we should cache the current request |
||
119 | * |
||
120 | * @param MvcEvent $mvcEvent |
||
121 | * @return bool |
||
122 | */ |
||
123 | protected function shouldCacheRequest(MvcEvent $mvcEvent) |
||
137 | |||
138 | /** |
||
139 | * @param array $tags |
||
140 | * @param bool|null $disjunction |
||
141 | * @return bool |
||
142 | * @throws UnsupportedAdapterException |
||
143 | */ |
||
144 | public function clearByTags(array $tags = array(), $disjunction = null) |
||
157 | |||
158 | /** |
||
159 | * Cache tags to use for this page |
||
160 | * |
||
161 | * @param MvcEvent $event |
||
162 | * @return array |
||
163 | */ |
||
164 | public function getTags(MvcEvent $event) |
||
180 | |||
181 | /** |
||
182 | * @param string $eventName |
||
183 | * @param MvcEvent|null $mvcEvent |
||
184 | * @return CacheEvent |
||
185 | */ |
||
186 | protected function createCacheEvent($eventName, MvcEvent $mvcEvent = null) |
||
195 | |||
196 | /** |
||
197 | * @return StorageInterface |
||
198 | */ |
||
199 | public function getCacheStorage() |
||
203 | |||
204 | /** |
||
205 | * @param StorageInterface $cacheStorage |
||
206 | * @return self |
||
207 | */ |
||
208 | public function setCacheStorage($cacheStorage) |
||
214 | |||
215 | /** |
||
216 | * @return ModuleOptions |
||
217 | */ |
||
218 | public function getOptions() |
||
222 | |||
223 | /** |
||
224 | * @param ModuleOptions $options |
||
225 | * @return self |
||
226 | */ |
||
227 | public function setOptions($options) |
||
233 | |||
234 | /** |
||
235 | * Inject an EventManager instance |
||
236 | * |
||
237 | * @param EventManagerInterface $eventManager |
||
238 | * @return self |
||
239 | */ |
||
240 | public function setEventManager(EventManagerInterface $eventManager) |
||
248 | |||
249 | /** |
||
250 | * Retrieve the event manager |
||
251 | * |
||
252 | * Lazy-loads an EventManager instance if none registered. |
||
253 | * |
||
254 | * @return EventManagerInterface |
||
255 | */ |
||
256 | public function getEventManager() |
||
264 | |||
265 | /** |
||
266 | * @return IdGeneratorInterface |
||
267 | */ |
||
268 | public function getIdGenerator() |
||
272 | |||
273 | /** |
||
274 | * @param IdGeneratorInterface $idGenerator |
||
275 | */ |
||
276 | public function setIdGenerator($idGenerator = null) |
||
280 | } |
||
281 |