@@ -182,9 +182,18 @@ Tagging
182
182
version 2.1.
183
183
184
184
To support :doc: `cache tags <response-tagging >`, register the
185
- ``PurgeTagsListener ``. For this listener to work, you must use the
186
- :ref: `TaggableStore <taggablestore >` provided in this library, instead of the
187
- default cache implementation.
185
+ ``PurgeTagsListener ``. The purge listener needs the special ``Toflar\Psr6Store ``
186
+ cache store with tag support.
187
+
188
+ .. note ::
189
+
190
+ Symfony's ``HttpCache `` store implementation does not support tags.
191
+ Therefore, you need the `Toflar Psr6Store `_ which implements the Symfony
192
+ Store interface but supports cache tagging. See the project README for more
193
+ information on the store.
194
+
195
+ To install the store, run
196
+ ``composer require toflar/psr6-symfony-http-cache-store dev-master ``.
188
197
189
198
Purging tags is only allowed from the same machine by default. To change this,
190
199
you have the same configuration options as with the ``PurgeListener ``. *Only
@@ -210,135 +219,33 @@ configure the HTTP method and header used for tag purging:
210
219
**default **: ``X-Cache-Tags ``
211
220
212
221
To get cache tagging support, register the ``PurgeTagsListener `` and use the
213
- ``TaggableStore `` in your ``AppCache ``::
222
+ ``Psr6Store `` in your ``AppCache ``::
214
223
215
224
// app/AppCache.php
216
225
217
- use FOS\HttpCache\SymfonyCache\TaggableStore ;
226
+ use Toflar\Psr6Store ;
218
227
use FOS\HttpCache\SymfonyCache\PurgeTagsListener;
219
228
220
229
// ...
221
230
222
231
/**
223
- * Overwrite constructor to register the TaggableStore .
232
+ * Overwrite constructor to register the Psr6Store and PurgeTagsListener .
224
233
*/
225
234
public function __construct(
226
235
HttpKernelInterface $kernel,
227
236
SurrogateInterface $surrogate = null,
228
237
array $options = []
229
238
) {
230
- $store = new TaggableStore(['cache_directory' => $kernel->getCacheDir()]);
239
+ $store = new Psr6Store([
240
+ 'cache_directory' => $kernel->getCacheDir(),
241
+ 'cache_tags_header' => 'X-Cache-Tags',
242
+ ]);
231
243
232
244
parent::__construct($kernel, $store, $surrogate, $options);
233
245
234
246
$this->addSubscriber(new PurgeTagsListener());
235
247
}
236
248
237
- .. _taggablestore :
238
-
239
- TaggableStore
240
- ^^^^^^^^^^^^^
241
-
242
- .. versionadded :: 2.1
243
-
244
- The ``TaggableStore `` has been added in version 2.1.
245
-
246
- .. note ::
247
-
248
- You need at least versions 3.4 of ``symfony/cache `` and ``symfony/lock ``
249
- to use this feature. Add the following lines to your ``composer.json `` and run
250
- ``composer update ``:
251
-
252
- "symfony/lock": "^3.4",
253
- "symfony/cache": "^3.4",
254
-
255
- Symfony's ``HttpCache `` store implementation does not support tags. Therefore,
256
- this library ships with a ``TaggableStore `` that is build on top of PSR-6 to
257
- provide this functionality.
258
-
259
- Even if you do not want to invalidate cache entries by tags, you might be
260
- interested in using the ``TaggableStore ``, as this store leverages the
261
- functionality of PSR-6 to prune expired cache entries to free up disk space.
262
-
263
- By default, the ``TaggableStore `` prunes the cache after a configurable number
264
- of cache write operations. You can disable automatic pruning, e.g. if you set
265
- up a cron job to prune, by setting the option ``prune_threshold `` to ``0 ``.
266
-
267
- Use the ``TaggableStore `` in your ``AppCache ``::
268
-
269
- // app/AppCache.php
270
-
271
- use FOS\HttpCache\SymfonyCache\PurgeTagsListener;
272
-
273
- // ...
274
-
275
- /**
276
- * Overwrite constructor to register the TaggableStore.
277
- */
278
- public function __construct(
279
- HttpKernelInterface $kernel,
280
- SurrogateInterface $surrogate = null,
281
- array $options = []
282
- ) {
283
- $store = new TaggableStore(['cache_directory' => $kernel->getCacheDir()]);
284
-
285
- parent::__construct($kernel, $store, $surrogate, $options);
286
- }
287
-
288
- The ``TaggableStore `` can be configured by passing an array of ``$options `` as a
289
- second argument:
290
-
291
- * **cache_directory **: Path to the cache directory for the default cache
292
- adapter and lock factory.
293
-
294
- Either this or both cache and lock_factory are required.
295
-
296
- **Type **: ``string ``
297
-
298
- * **cache **: Explicitly specify the cache adapter you want to use. Make sure
299
- that lock and cache have the same scope. *See warning below! *
300
-
301
- **Type **: ``Symfony\Component\Cache\Adapter\TagAwareAdapterInterface ``
302
- **Default **: ``FilesystemAdapter `` instance with cache_directory
303
-
304
- * **lock_factory **: Explicitly specify the lock factory you want to use. Make
305
- sure that lock and cache have the same scope. *See warning below! *
306
-
307
- **Type **: ``Symfony\Component\Lock\Factory ``
308
- **Default **: ``Factory `` with ``SemaphoreStore `` if supported, ``FlockStore `` otherwise
309
-
310
- * **prune_threshold **: Configure the number of write actions until the store
311
- will prune the expired cache entries. Pass 0 to disable automated pruning.
312
-
313
- **Type **: ``int ``
314
- **Default **: 500
315
-
316
- * **purge_tags_header **: The HTTP header name used to check for tags
317
-
318
- **Type **: ``string ``
319
- **Default **: ``X-Cache-Tags ``
320
-
321
- .. warning ::
322
-
323
- It is possible to configure other cache adapters or lock stores than the
324
- filesystem ones. Only do this if you are sure of what you are doing. In
325
- `this pull request `_ Fabien Potentier refused to add PSR-6 store support to
326
- the Symfony ``AppCache `` with the following arguments:
327
-
328
- * Using a filesystem allows for ``opcache `` to make the cache very
329
- effective;
330
- * The cache contains some PHP (when using ESI for instance) and storing
331
- PHP in anything else than a filesystem would mean ``eval() ``-ing
332
- strings coming from Redis / Memcache /...;
333
- * HttpCache is triggered very early and does not have access to the
334
- container or anything else really. And it should stay that way to be
335
- efficient.
336
-
337
- While the first and third point depend on what you do and need, be sure to
338
- respect the second point. If you use network enabled caches like Redis or
339
- Memcache, make sure that they are not shared with other systems in your
340
- hosting center to avoid code injection.
341
-
342
249
.. _symfony-cache user context :
343
250
344
251
User Context
@@ -438,4 +345,4 @@ and at the HTML body of the response.
438
345
439
346
.. _HttpCache : http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy
440
347
.. _HttpKernel : http://symfony.com/doc/current/components/http_kernel.html
441
- .. _ this pull request : https://github.com/symfony/ symfony/pull/20061#issuecomment-313339092
348
+ .. _ Toflar Psr6Store : https://github.com/Toflar/psr6- symfony-http-cache-store
0 commit comments