10000 remove TaggableStore as its now in its own package · FriendsOfSymfony/FOSHttpCache@0290e22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0290e22

Browse files
committed
remove TaggableStore as its now in its own package
1 parent 2ae81c0 commit 0290e22

File tree

8 files changed

+33
-1138
lines changed

8 files changed

+33
-1138
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
99
* [Testing] Upgraded phpunit to 5.7 / 6. If you use anything from the
1010
`FOS\HttpCache\Test` namespace you need to update your project to use
1111
PHPUnit 6 (or 5.7, if you are using PHP 5.6).
12-
* [Symfony HttpCache] Added a `TaggableStore` and a `PurgeTagsListener` for tag
13-
based invalidation with the Symfony `HttpCache` reverse caching proxy. The
14-
`TaggableStore` builds on PSR-6 cache and supports pruning expired cache
15-
entries.
12+
* [Symfony HttpCache] Added a `TaggableStore` for tag based invalidation with
13+
the Symfony `HttpCache` reverse caching proxy. This requires the newly
14+
created [Toflar Psr6Store](https://github.com/Toflar/psr6-symfony-http-cache-store)
15+
built on PSR-6 cache and supporting pruning expired cache entries.
1616

1717
2.0.2
1818
-----

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
"php-http/mock-client": "^0.3.2",
3737
"symfony/process": "^2.3||^3.0",
3838
"symfony/http-kernel": "^2.3||^3.0",
39-
"symfony/lock": "^3.4@dev",
40-
"symfony/cache": "^3.4@dev",
41-
"phpunit/phpunit": "^5.7 || ^6.0"
39+
"phpunit/phpunit": "^5.7 || ^6.0",
40+
"toflar/psr6-symfony-http-cache-store": "dev-master"
4241
},
4342
"suggest": {
4443
"friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework",

doc/spelling_word_list.txt

Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ admin
22
backend
33
cacheable
44
config
5-
cron
65
css
7-
filesystem
86
hostname
97
hostnames
108
http
@@ -14,10 +12,7 @@ localhost
1412
middleware
1513
middlewares
1614
namespace
17-
Memcache
1815
nginx
19-
Potentier
20-
Redis
2116
roundtrip
2217
symfony
2318
whitelisted
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,18 @@ Tagging
182182
version 2.1.
183183

184184
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``.
188197

189198
Purging tags is only allowed from the same machine by default. To change this,
190199
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:
210219
**default**: ``X-Cache-Tags``
211220

212221
To get cache tagging support, register the ``PurgeTagsListener`` and use the
213-
``TaggableStore`` in your ``AppCache``::
222+
``Psr6Store`` in your ``AppCache``::
214223

215224
// app/AppCache.php
216225

217-
use FOS\HttpCache\SymfonyCache\TaggableStore;
226+
use Toflar\Psr6Store;
218227
use FOS\HttpCache\SymfonyCache\PurgeTagsListener;
219228

220229
// ...
221230

222231
/**
223-
* Overwrite constructor to register the TaggableStore.
232+
* Overwrite constructor to register the Psr6Store and PurgeTagsListener.
224233
*/
225234
public function __construct(
226235
HttpKernelInterface $kernel,
227236
SurrogateInterface $surrogate = null,
228237
array $options = []
229238
) {
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+
]);
231243

232244
parent::__construct($kernel, $store, $surrogate, $options);
233245

234246
$this->addSubscriber(new PurgeTagsListener());
235247
}
236248

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-
342249
.. _symfony-cache user context:
343250

344251
User Context
@@ -438,4 +345,4 @@ and at the HTML body of the response.
438345

439346
.. _HttpCache: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy
440347
.. _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
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace FOS\HttpCache\SymfonyCache;
1313

14-
use FOS\HttpCache\ProxyClient\Symfony;
1514
use Symfony\Component\HttpFoundation\Response;
1615
use Symfony\Component\OptionsResolver\OptionsResolver;
16+
use Toflar\Psr6HttpCacheStore\Psr6Store;
1717

1818
/**
1919
* Purge tags handler for the symfony built-in HttpCache.
@@ -94,9 +94,9 @@ public function handlePurgeTags(CacheEvent $event)
9494
$response = new Response();
9595
$store = $event->getKernel()->getStore();
9696

97-
if (!$store instanceof TaggableStore) {
97+
if (!$store instanceof Psr6Store) {
9898
$response->setStatusCode(400);
99-
$response->setContent('Store must be an instance of TaggableStore! Check your proxy configuration!');
99+
$response->setContent('Store must be an instance of Toflar\Psr6Store! Check your proxy configuration!');
100100

101101
$event->setResponse($response);
102102