Skip to content

Commit 4ed2a70

Browse files
committed
Change doc for abstract tag changes
1 parent e412091 commit 4ed2a70

File tree

7 files changed

+116
-100
lines changed

7 files changed

+116
-100
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+
When you are using :doc:`response tagging <response-tagging>`, you can invalidate
95+
all responses that where tagged with a specific label.
96+
97+
Invalidate a tag::
98+
99+
$cacheInvalidator->invalidateTags(['blog-post-44'])->flush();
100+
101+
See below for the :ref:`flush() <flush>` method.
102+
103+
Invalidate several tags::
104+
105+
$cacheInvalidator
106+
->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/invalidation-handlers.rst

Lines changed: 0 additions & 98 deletions
This file was deleted.

doc/proxy-clients.rst

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

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

94+
-.. _varnish_custom_tags_header:
95+
96+
Another optional parameter available on Varnish client is ``tagsHeader``, which allows you to
97+
change the default HTTP header used for tagging, ``X-Cache-Tags``::
98+
99+
$varnish = new Varnish($servers, 'example.com', $adapter, 'X-Custom-Tags-Header');
100+
101+
Make sure to reflect this change in your :doc:`caching proxy configuration <proxy-configuration>`.
102+
94103
.. note::
95104

96105
To make invalidation work, you need to :doc:`configure Varnish <varnish-configuration>` accordingly.
@@ -267,5 +276,6 @@ Varnish client::
267276
Make sure to add any headers that you want to ban on to your
268277
:doc:`proxy configuration <proxy-configuration>`.
269278

279+
.. _header: http://php.net/header
270280
.. _HTTP Adapter: http://php-http.readthedocs.org/en/latest/
271281
.. _PSR-7 message implementation: https://packagist.org/providers/psr/http-message-implementation

doc/response-tagging.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Response Tagging
2+
================
3+
4+
The ``ResponseTagger`` helps you keep track tags for a response, which can be
5+
added to response headers that you can later use to invalidate all cache
6+
entries with that tag.
7+
8+
.. _tags:
9+
10+
Setup
11+
~~~~~
12+
13+
.. note::
14+
15+
Make sure to :doc:`configure your proxy <proxy-configuration>` for tagging first.
16+
17+
The response tagger is a decorator around a proxy client that implements
18+
the ``TagsInterface``, handling adding tags to responses::
19+
20+
use FOS\HttpCache\ResponseTagger;
21+
22+
// $proxyClient already created, implementing FOS\HttpCache\ProxyClient\Invalidation\TagsInterface
23+
$responseTagger = new ResponseTagger($proxyClient);
24+
25+
Usage
26+
~~~~~
27+
28+
With tags you can group related representations so it becomes easier to
29+
invalidate them. You will have to make sure your web application adds the
30+
correct tags on all responses. You can add tags to the response using::
31+
32+
$responseTagger->addTags(['tag-two', 'group-a']);
33+
34+
Before any content is sent out, you need to send the tag header_::
35+
36+
header(sprintf('%s: %s'),
37+
$responseTagger->getTagsHeaderName(),
38+
$responseTagger->getTagsHeaderValue()
39+
);
40+
41+
.. tip::
42+
43+
If you are using Symfony with the FOSHttpCacheBundle_, the tags
44+
added to ``ResponseTagger`` are added to the response automatically.
45+
You also have `additional methods of defining tags`_ with
46+
annotations and on URL patterns.
47+
48+
Assume you sent four responses:
49+
50+
+------------+-------------------------+
51+
| Response: | ``X-Cache-Tags`` header:|
52+
+============+=========================+
53+
| ``/one`` | ``tag-one`` |
54+
+------------+-------------------------+
55+
| ``/two`` | ``tag-two, group-a`` |
56+
+------------+-------------------------+
57+
| ``/three`` | ``tag-three, group-a`` |
58+
+------------+-------------------------+
59+
| ``/four`` | ``tag-four, group-b`` |
60+
+------------+-------------------------+
61+
62+
You can now invalidate some URLs using tags::
63+
64+
$tagHandler->invalidateTags(['group-a', 'tag-four'])->flush();
65+
66+
This will ban all requests having either the tag ``group-a`` /or/ ``tag-four``.
67+
In the above example, this will invalidate ``/two``, ``/three`` and ``/four``.
68+
Only ``/one`` will stay in the cache.
69+
70+
.. note::
71+
72+
For further reading on tag invalidation see :doc:`cache-invalidator page <cache-invalidator>`.
73+
For changing the cache header, :doc:`configure your proxy <proxy-clients>`.
74+
75+
.. _header: http://php.net/header
76+
.. _additional methods of defining tags: http://foshttpcachebundle.readthedocs.org/en/latest/features/tagging.html

doc/varnish-configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ using an ``X-Cache-Tags`` header.
180180
If you need to use a different tag for the headers than the default
181181
``X-Cache-Tags`` used in ``fos_ban.vcl``, you will have to write your own VCL
182182
code for tag invalidation and change the tagging header
183-
:ref:`configured in the cache invalidator <custom_tags_header>`. Your custom
183+
:ref:`configured in the cache invalidator <varnish_custom_tags_header>`. Your custom
184184
VCL will look like this:
185185

186186
.. configuration-block::

0 commit comments

Comments
 (0)