1
1
Response Tagging
2
2
================
3
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
4
+ The ``ResponseTagger `` helps you keep track of tags for a response. It can add
5
+ the tags as a response header that you can later use to invalidate all cache
6
6
entries with that tag.
7
7
8
8
.. _tags :
@@ -12,23 +12,40 @@ Setup
12
12
13
13
.. note ::
14
14
15
- Make sure to :doc: `configure your proxy <proxy-configuration >` for tagging first.
15
+ Make sure to :doc: `configure your proxy <proxy-configuration >` for tagging
16
+ first.
16
17
17
- The response tagger is a decorator around a proxy client that implements
18
- the ``TagCapable `` interface, handling adding tags to responses::
18
+ The response tagger uses an instance of ``TagHeaderFormatter `` to know the
19
+ header name used to mark tags on the content and to format the tags into the
20
+ correct header value. This library ships with a
21
+ ``CommaSeparatedTagHeaderFormatter `` that formats an array of tags into a
22
+ comma-separated list. This format is expected for invalidation with the
23
+ Varnish reverse proxy. When using the default settings, everything is created
24
+ automatically and the ``X-Cache-Tags `` header will be used::
19
25
20
26
use FOS\HttpCache\ResponseTagger;
21
27
22
- // $proxyClient already created, implementing FOS\HttpCache\ProxyClient\Invalidation\TagCapable
23
- $responseTagger = new ResponseTagger($proxyClient);
28
+ $responseTagger = new ResponseTagger();
24
29
25
30
.. _response_tagger_optional_parameters :
26
31
32
+ If you need a different behavior, you can provide your own implementation of
33
+ the ``TagHeaderFormatter `` interface. But be aware that your
34
+ :ref: `Varnish configuration <varnish_tagging >` has to match with the tag on the response.
35
+ For example, to use a different header name::
36
+
37
+ use FOS\HttpCache\ResponseTagger;
38
+ use FOS\HttpCache\TagHeaderFormatter;
39
+
40
+ $formatter = new CommaSeparatedTagHeaderFormatter('Custom-Header-Name');
41
+ $responseTagger = new ResponseTagger(['header_formatter' => $formatter]);
42
+
27
43
The response tagger validates tags that you set. By default, it simply ignores
28
- empty strings. You can set the response tagger to strict mode to have it throw
29
- an ``InvalidTagException `` on empty tags::
44
+ empty strings and does not add them to the list of tags. You can set the
45
+ response tagger to strict mode to have it throw an ``InvalidTagException `` on
46
+ empty tags::
30
47
31
- $responseTagger = new ResponseTagger($proxyClient, ['strict' => true]);
48
+ $responseTagger = new ResponseTagger(['strict' => true]);
32
49
33
50
Usage
34
51
~~~~~
0 commit comments