1 | <?php |
||
37 | class CacheInvalidator |
||
38 | { |
||
39 | /** |
||
40 | * Value to check support of invalidatePath operation. |
||
41 | */ |
||
42 | const PATH = 'path'; |
||
43 | |||
44 | /** |
||
45 | * Value to check support of refreshPath operation. |
||
46 | */ |
||
47 | const REFRESH = 'refresh'; |
||
48 | |||
49 | /** |
||
50 | * Value to check support of invalidate and invalidateRegex operations. |
||
51 | */ |
||
52 | const INVALIDATE = 'invalidate'; |
||
53 | |||
54 | /** |
||
55 | * Value to check support of invalidateTags operation. |
||
56 | */ |
||
57 | const TAGS = 'tags'; |
||
58 | |||
59 | /** |
||
60 | * Value to check support of clearCache operation. |
||
61 | */ |
||
62 | const CLEAR = 'clear'; |
||
63 | |||
64 | /** |
||
65 | * @var ProxyClient |
||
66 | */ |
||
67 | private $cache; |
||
68 | |||
69 | /** |
||
70 | * @var EventDispatcherInterface |
||
71 | 12 | */ |
|
72 | private $eventDispatcher; |
||
73 | 12 | ||
74 | 12 | /** |
|
75 | * Constructor. |
||
76 | * |
||
77 | * @param ProxyClient $cache HTTP cache |
||
78 | */ |
||
79 | public function __construct(ProxyClient $cache) |
||
83 | |||
84 | /** |
||
85 | * Check whether this invalidator instance supports the specified |
||
86 | * operation. |
||
87 | * |
||
88 | * Support for PATH means invalidatePath will work, REFRESH means |
||
89 | * refreshPath works, TAGS means that invalidateTags works and |
||
90 | 3 | * INVALIDATE is for the invalidate and invalidateRegex methods. |
|
91 | * |
||
92 | * @param string $operation one of the class constants |
||
93 | 3 | * |
|
94 | 2 | * @return bool |
|
95 | 3 | * |
|
96 | 2 | * @throws InvalidArgumentException |
|
97 | 3 | */ |
|
98 | 2 | public function supports($operation) |
|
120 | 1 | ||
121 | /** |
||
122 | 2 | * Set event dispatcher - may only be called once. |
|
123 | 2 | * |
|
124 | * @param EventDispatcherInterface $eventDispatcher |
||
125 | * |
||
126 | * @throws \Exception when trying to override the event dispatcher |
||
127 | */ |
||
128 | public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) |
||
137 | |||
138 | /** |
||
139 | * Get the event dispatcher used by the cache invalidator. |
||
140 | * |
||
141 | * @return EventDispatcherInterface |
||
142 | */ |
||
143 | public function getEventDispatcher() |
||
151 | 1 | ||
152 | /** |
||
153 | * Invalidate a path or URL. |
||
154 | * |
||
155 | 1 | * @param string $path Path or URL |
|
156 | * @param array $headers HTTP headers (optional) |
||
157 | 1 | * |
|
158 | * @throws UnsupportedProxyOperationException |
||
159 | * |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function invalidatePath($path, array $headers = []) |
||
172 | 1 | ||
173 | /** |
||
174 | 1 | * Refresh a path or URL. |
|
175 | * |
||
176 | * @param string $path Path or URL |
||
177 | * @param array $headers HTTP headers (optional) |
||
178 | 1 | * |
|
179 | * @see RefreshCapable::refresh() |
||
180 | 1 | * |
|
181 | * @throws UnsupportedProxyOperationException |
||
182 | * |
||
183 | * @return $this |
||
184 | */ |
||
185 | public function refreshPath($path, array $headers = []) |
||
195 | |||
196 | /** |
||
197 | 1 | * Invalidate all cached objects matching the provided HTTP headers. |
|
198 | * |
||
199 | 1 | * Each header is a a POSIX regular expression, for example |
|
200 | * ['X-Host' => '^(www\.)?(this|that)\.com$'] |
||
201 | * |
||
202 | * @see BanCapable::ban() |
||
203 | 1 | * |
|
204 | * @param array $headers HTTP headers that path must match to be banned |
||
205 | 1 | * |
|
206 | * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests |
||
207 | * |
||
208 | * @return $this |
||
209 | */ |
||
210 | public function invalidate(array $headers) |
||
220 | |||
221 | 2 | /** |
|
222 | * Remove/Expire cache objects based on cache tags. |
||
223 | * |
||
224 | 2 | * @see TagCapable::tags() |
|
225 | * |
||
226 | 2 | * @param array $tags Tags that should be removed/expired from the cache |
|
227 | * |
||
228 | * @throws UnsupportedProxyOperationException If HTTP cache does not support Tags invalidation |
||
229 | * |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function invalidateTags(array $tags) |
||
241 | |||
242 | /** |
||
243 | * Invalidate URLs based on a regular expression for the URI, an optional |
||
244 | * content type and optional limit to certain hosts. |
||
245 | * |
||
246 | * The hosts parameter can either be a regular expression, e.g. |
||
247 | * '^(www\.)?(this|that)\.com$' or an array of exact host names, e.g. |
||
248 | * ['example.com', 'other.net']. If the parameter is empty, all hosts |
||
249 | * are matched. |
||
250 | * |
||
251 | 1 | * @see BanCapable::banPath() |
|
252 | * |
||
253 | 1 | * @param string $path Regular expression pattern for URI to |
|
254 | * invalidate |
||
255 | * @param string $contentType Regular expression pattern for the content |
||
256 | * type to limit banning, for instance 'text' |
||
257 | 1 | * @param array|string $hosts Regular expression of a host name or list of |
|
258 | * exact host names to limit banning |
||
259 | 1 | * |
|
260 | * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests |
||
261 | * |
||
262 | * @return $this |
||
263 | */ |
||
264 | public function invalidateRegex($path, $contentType = null, $hosts = null) |
||
274 | 1 | ||
275 | 1 | /** |
|
276 | 1 | * Clear the cache completely. |
|
277 | 1 | * |
|
278 | 1 | * @throws UnsupportedProxyOperationException if HTTP cache does not support clearing the cache completely |
|
279 | 1 | * |
|
280 | 1 | * @return $this |
|
281 | */ |
||
282 | public function clearCache() |
||
292 | |||
293 | /** |
||
294 | * Send all pending invalidation requests. |
||
295 | * |
||
296 | * @return int the number of cache invalidations performed per caching server |
||
297 | * |
||
298 | * @throws ExceptionCollection if any errors occurred during flush |
||
299 | */ |
||
300 | public function flush() |
||
318 | } |
||
319 |