1 | <?php |
||
36 | class CacheInvalidator |
||
37 | { |
||
38 | /** |
||
39 | * Value to check support of invalidatePath operation. |
||
40 | */ |
||
41 | const PATH = 'path'; |
||
42 | |||
43 | /** |
||
44 | * Value to check support of refreshPath operation. |
||
45 | */ |
||
46 | const REFRESH = 'refresh'; |
||
47 | |||
48 | /** |
||
49 | * Value to check support of invalidate and invalidateRegex operations. |
||
50 | */ |
||
51 | const INVALIDATE = 'invalidate'; |
||
52 | |||
53 | /** |
||
54 | * Value to check support of invalidateTags operation. |
||
55 | */ |
||
56 | const TAGS = 'tags'; |
||
57 | |||
58 | /** |
||
59 | * @var ProxyClient |
||
60 | */ |
||
61 | private $cache; |
||
62 | |||
63 | /** |
||
64 | * @var EventDispatcherInterface |
||
65 | */ |
||
66 | private $eventDispatcher; |
||
67 | |||
68 | /** |
||
69 | * Constructor. |
||
70 | * |
||
71 | 12 | * @param ProxyClient $cache HTTP cache |
|
72 | */ |
||
73 | 12 | public function __construct(ProxyClient $cache) |
|
77 | |||
78 | /** |
||
79 | * Check whether this invalidator instance supports the specified |
||
80 | * operation. |
||
81 | * |
||
82 | * Support for PATH means invalidatePath will work, REFRESH means |
||
83 | * refreshPath works, TAGS means that invalidateTags works and |
||
84 | * INVALIDATE is for the invalidate and invalidateRegex methods. |
||
85 | * |
||
86 | * @param string $operation one of the class constants |
||
87 | * |
||
88 | * @return bool |
||
89 | * |
||
90 | 3 | * @throws InvalidArgumentException |
|
91 | */ |
||
92 | public function supports($operation) |
||
112 | |||
113 | /** |
||
114 | * Set event dispatcher - may only be called once. |
||
115 | 2 | * |
|
116 | * @param EventDispatcherInterface $eventDispatcher |
||
117 | 2 | * |
|
118 | * @return $this |
||
119 | * |
||
120 | 1 | * @throws \Exception when trying to override the event dispatcher |
|
121 | */ |
||
122 | 2 | public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) |
|
131 | |||
132 | 2 | /** |
|
133 | 1 | * Get the event dispatcher used by the cache invalidator. |
|
134 | * |
||
135 | * @return EventDispatcherInterface |
||
136 | 2 | */ |
|
137 | public function getEventDispatcher() |
||
145 | |||
146 | /** |
||
147 | * Invalidate a path or URL. |
||
148 | * |
||
149 | 1 | * @param string $path Path or URL |
|
150 | * @param array $headers HTTP headers (optional) |
||
151 | 1 | * |
|
152 | * @throws UnsupportedProxyOperationException |
||
153 | * |
||
154 | * @return $this |
||
155 | 1 | */ |
|
156 | public function invalidatePath($path, array $headers = []) |
||
166 | |||
167 | /** |
||
168 | * Refresh a path or URL. |
||
169 | * |
||
170 | * @param string $path Path or URL |
||
171 | * @param array $headers HTTP headers (optional) |
||
172 | 1 | * |
|
173 | * @see RefreshCapable::refresh() |
||
174 | 1 | * |
|
175 | * @throws UnsupportedProxyOperationException |
||
176 | * |
||
177 | * @return $this |
||
178 | 1 | */ |
|
179 | public function refreshPath($path, array $headers = []) |
||
189 | |||
190 | /** |
||
191 | * Invalidate all cached objects matching the provided HTTP headers. |
||
192 | * |
||
193 | * Each header is a a POSIX regular expression, for example |
||
194 | * ['X-Host' => '^(www\.)?(this|that)\.com$'] |
||
195 | * |
||
196 | * @see BanCapable::ban() |
||
197 | 1 | * |
|
198 | * @param array $headers HTTP headers that path must match to be banned |
||
199 | 1 | * |
|
200 | * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests |
||
201 | * |
||
202 | * @return $this |
||
203 | 1 | */ |
|
204 | public function invalidate(array $headers) |
||
214 | |||
215 | /** |
||
216 | * Remove/Expire cache objects based on cache tags. |
||
217 | * |
||
218 | * @see TagCapable::tags() |
||
219 | 2 | * |
|
220 | * @param array $tags Tags that should be removed/expired from the cache |
||
221 | 2 | * |
|
222 | * @throws UnsupportedProxyOperationException If HTTP cache does not support Tags invalidation |
||
223 | * |
||
224 | 2 | * @return $this |
|
225 | */ |
||
226 | 2 | public function invalidateTags(array $tags) |
|
235 | |||
236 | /** |
||
237 | * Invalidate URLs based on a regular expression for the URI, an optional |
||
238 | * content type and optional limit to certain hosts. |
||
239 | * |
||
240 | * The hosts parameter can either be a regular expression, e.g. |
||
241 | * '^(www\.)?(this|that)\.com$' or an array of exact host names, e.g. |
||
242 | * ['example.com', 'other.net']. If the parameter is empty, all hosts |
||
243 | * are matched. |
||
244 | * |
||
245 | * @see BanCapable::banPath() |
||
246 | * |
||
247 | * @param string $path Regular expression pattern for URI to |
||
248 | * invalidate |
||
249 | * @param string $contentType Regular expression pattern for the content |
||
250 | * type to limit banning, for instance 'text' |
||
251 | 1 | * @param array|string $hosts Regular expression of a host name or list of |
|
252 | * exact host names to limit banning |
||
253 | 1 | * |
|
254 | * @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests |
||
255 | * |
||
256 | * @return $this |
||
257 | 1 | */ |
|
258 | public function invalidateRegex($path, $contentType = null, $hosts = null) |
||
268 | |||
269 | 3 | /** |
|
270 | * Send all pending invalidation requests. |
||
271 | * |
||
272 | 3 | * @return int the number of cache invalidations performed per caching server |
|
273 | 1 | * |
|
274 | 1 | * @throws ExceptionCollection if any errors occurred during flush |
|
275 | 1 | */ |
|
276 | 1 | public function flush() |
|
294 | } |
||
295 |