11Response Tagging
22================
33
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
66entries with that tag.
77
88.. _tags :
@@ -12,23 +12,40 @@ Setup
1212
1313.. note ::
1414
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.
1617
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::
1925
2026 use FOS\HttpCache\ResponseTagger;
2127
22- // $proxyClient already created, implementing FOS\HttpCache\ProxyClient\Invalidation\TagCapable
23- $responseTagger = new ResponseTagger($proxyClient);
28+ $responseTagger = new ResponseTagger();
2429
2530.. _response_tagger_optional_parameters :
2631
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+
2743The 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::
3047
31- $responseTagger = new ResponseTagger($proxyClient, ['strict' => true]);
48+ $responseTagger = new ResponseTagger(['strict' => true]);
3249
3350Usage
3451~~~~~
0 commit comments