Skip to content

Commit 4a83ade

Browse files
committed
Change doc for abstract tag changes
1 parent b046f61 commit 4a83ade

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
1818
caching proxy.
1919
* Refactored the proxy client test system into traits. Removed ProxyTestCase,
2020
use the traits `CacheAssertions` and `HttpCaller` instead.
21+
* Abstracting tags by adding new `TagsInterface` for ProxyClients, as part of that also:
22+
BC break: Moved tag invalidation to `CacheInvalidator`, and rename TagHandler to ResponseTagger.
2123

2224
1.4.0
2325
-----

doc/cache-invalidator.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ Refresh a URL with added header(s)::
8282

8383
.. _invalidate regex:
8484

85+
86+
Invalidating by Tags
87+
--------------------
88+
89+
.. note::
90+
91+
Make sure to :doc:`configure your proxy <proxy-configuration>` for tagging first,
92+
in the case of Varnish this is powered by banning.
93+
94+
By taking advantage of :doc:`response tagging <response-tagging>`, invalidation
95+
all URLs that has been tagged with a given tag becomes possible.
96+
97+
98+
Invalidate a tag::
99+
100+
$cacheInvalidator->invalidateTags(['blog-post-44'])->flush();
101+
102+
See below for the :ref:`flush() <flush>` method.
103+
104+
Invalidate several tags::
105+
106+
$cacheInvalidator->invalidateTags(['type-65', 'location-3'])
107+
->flush()
108+
;
109+
110+
85111
Invalidating With a Regular Expression
86112
--------------------------------------
87113

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Contents:
2828
proxy-configuration
2929
proxy-clients
3030
cache-invalidator
31-
invalidation-handlers
31+
response-tagging
3232
user-context
3333

3434
testing-your-application

doc/proxy-clients.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ include that port in the base URL::
9191

9292
$varnish = new Varnish($servers, 'my-cool-app.com:8080');
9393

94+
Another optional parameter available on Varnish client is ``tagsHeader``, which allows you to
95+
change the default HTTP header used for tags, ``X-Cache-Tags``::
96+
97+
$varnish = new Varnish($servers, 'example.com', $adapter, 'X-Custom-Tags-Header');
98+
9499
.. note::
95100

96101
To make invalidation work, you need to :doc:`configure Varnish <varnish-configuration>` accordingly.

doc/invalidation-handlers.rst renamed to doc/response-tagging.rst

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Extra Invalidation Handlers
2-
===========================
1+
Response Tagging
2+
================
33

4-
This library provides decorators that build on top of the ``CacheInvalidator``
5-
to simplify common operations.
4+
This library provides a service to handle tagging of responses ``ResponseTagger``
5+
to simplify use of tags.
66

77
.. _tags:
88

9-
Tag Handler
10-
-----------
9+
Response Tagger
10+
---------------
1111

12-
The tag handler helps you to mark responses with tags that you can later use to
13-
invalidate all cache entries with that tag. Tag invalidation works only with a
14-
``CacheInvalidator`` that supports ``CacheInvalidator::INVALIDATE``.
12+
The ResponseTagger helps you to mark responses with tags that you can later use to
13+
invalidate all cache entries with that tag. Response Tagging and tag invalidation
14+
require a proxy client that implements ``TagsInterface``.
1515

1616
Setup
1717
~~~~~
@@ -20,29 +20,28 @@ Setup
2020

2121
Make sure to :doc:`configure your proxy <proxy-configuration>` for tagging first.
2222

23-
The tag handler is a decorator around the ``CacheInvalidator``. After
24-
:doc:`creating the invalidator <cache-invalidator>` with a proxy client
25-
that implements the ``BanInterface``, instantiate the ``TagHandler``::
23+
The response tagger is a decorator around a proxy client that implements
24+
the ``TagsInterface``, handling tags for the current response::
2625

27-
use FOS\HttpCache\Handler\TagHandler;
26+
use FOS\HttpCache\ResponseTagger;
2827

29-
// $cacheInvalidator already created as instance of FOS\HttpCache\CacheInvalidator
30-
$tagHandler = new TagHandler($cacheInvalidator);
28+
// $proxyClient already created, implementing FOS\HttpCache\ProxyClient\Invalidation\TagsInterface
29+
$responseTagger = new ResponseTagger($proxyClient);
3130

3231
Usage
3332
~~~~~
3433

3534
With tags you can group related representations so it becomes easier to
3635
invalidate them. You will have to make sure your web application adds the
37-
correct tags on all responses. You can add tags to the handler using::
36+
correct tags on all responses. You can add tags to the response using::
3837

39-
$tagHandler->addTags(['tag-two', 'group-a']);
38+
$responseTagger->addTags(['tag-two', 'group-a']);
4039

4140
Before any content is sent out, you need to send the tag header_::
4241

4342
header(sprintf('%s: %s'),
44-
$tagHandler->getTagsHeaderName(),
45-
$tagHandler->getTagsHeaderValue()
43+
$responseTagger->getTagsHeaderName(),
44+
$responseTagger->getTagsHeaderValue()
4645
);
4746

4847
.. tip::
@@ -75,21 +74,21 @@ Only ``/one`` will stay in the cache.
7574

7675
.. note::
7776

78-
Don't forget to call :ref:`flush <flush>` on the ``CacheInvalidator`` to commit the invalidations
79-
to the caching proxy.
80-
81-
.. _custom_tags_header:
77+
For further reading on tag invalidation see :doc:`cache-invalidator page <cache-invalidator>`.
78+
For changing the cache header, :doc:`configure your proxy <proxy-clients>`
8279

8380
Custom Tags Header
8481
~~~~~~~~~~~~~~~~~~
8582

83+
// TOOO: Move or change to reflect that this depends on Proxy Client.
84+
8685
Tagging uses a custom HTTP header to identify tags. You can change the default
8786
header ``X-Cache-Tags`` in the constructor::
8887

89-
use FOS\HttpCache\Handler\TagHandler;
88+
use FOS\HttpCache\ResponseTagger;
9089

9190
// $cacheInvalidator already created as instance of FOS\HttpCache\CacheInvalidator
92-
$tagHandler = new TagHandler($cacheInvalidator, 'My-Cache-Header');
91+
$responseTagger = new ResponseTagger($cacheInvalidator, 'My-Cache-Header');
9392

9493
Make sure to reflect this change in your
9594
:doc:`caching proxy configuration <proxy-configuration>`.

0 commit comments

Comments
 (0)