@@ -33,22 +33,41 @@ will be used throughout the Varnish examples on this page.
3333 trigger invalidation are whitelisted here. Otherwise, lost cache invalidation
3434 requests will lead to lots of confusion.
3535
36+ Provided Vcl Subroutines
37+ ~~~~~~~~~~~~~~~~~~~~~~~~
38+
39+ In order to ease configuration we provide a set of vcl subroutines in the resources/config directory.
40+ These can be directly included into ``your_varnish.vcl `` and the needed subroutines called
41+ from the respective vcl_* subroutines.
42+
43+ .. important ::
44+ When including one of the provided vcl you need to call all the defined subroutines
45+ or your configuration will not be valid.
46+
47+ See the respective sections below on how to configure usage of each of the provided vcl's.
48+
3649Purge
3750~~~~~
3851
3952To configure Varnish for `handling PURGE requests <https://www.varnish-cache.org/docs/3.0/tutorial/purging.html >`_:
4053
4154Purge removes a specific URL (including query strings) in all its variants (as specified by the ``Vary `` header).
4255
43- .. configuration-block ::
56+ Subroutines are provided in `` resources/config/varnis-[version]/fos_purge.vcl ``.
4457
45- .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/purge. vcl
46- :language: varnish4
47- :linenos:
58+ To enable support add the following to `` your_varnish. vcl``:
59+
60+ .. code-block :: varnish3
4861
49- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/purge.vcl
62+ include "path-to-config/varnish-[version]/fos_purge.vcl";
63+
64+ .. configuration-block ::
65+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/fos.vcl
66+ :language: varnish4
67+ :lines: 17,19,21-22
68+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/fos.vcl
5069 :language: varnish3
51- :linenos:
70+ :lines: 15,17,19-20,25-32
5271
5372Refresh
5473~~~~~~~
@@ -58,26 +77,44 @@ add the following to your Varnish configuration:
5877
5978Refresh invalidates a specific URL including the query string, but *not * its variants.
6079
61- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/refresh.vcl
62- :language: varnish3
63- :linenos:
80+ Subroutines are provided in ``fos_refresh.vcl ``
81+
82+ To enable support add the following to ``your_varnish.vcl ``:
83+
84+ .. code-block :: varnish3
85+
86+ include "path-to-config/varnish-[version]/fos_refresh.vcl";
87+
88+ .. configuration-block ::
89+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/fos.vcl
90+ :language: varnish4
91+ :lines: 17,20-22
92+
93+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/fos.vcl
94+ :language: varnish3
95+ :lines: 15,18-20
6496
6597Ban
6698~~~
6799
68100To configure Varnish for `handling BAN requests <https://www.varnish-software.com/static/book/Cache_invalidation.html#banning >`_:
69101
70- .. configuration-block ::
102+ Subroutines are provided in `` fos_ban.vcl ``
71103
72- .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/ban.vcl
104+ To enable support add the following to ``your_varnish.vcl ``:
105+
106+ .. code-block :: varnish3
107+
108+ include "path-to-config/varnish-[version]/fos_ban.vcl";
109+
110+ .. configuration-block ::
111+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/fos.vcl
73112 :language: varnish4
74- :lines: 1-7, 15-18, 20-
75- :linenos:
113+ :lines: 17-18,21-29
76114
77- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/ban .vcl
115+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/fos .vcl
78116 :language: varnish3
79- :lines: 1-7, 15-18, 20-
80- :linenos:
117+ :lines: 15-16,19-24,33-35
81118
82119Varnish contains a `ban lurker `_ that crawls the content to eventually throw out banned data even when it’s not requested by any client.
83120
@@ -88,23 +125,22 @@ Varnish contains a `ban lurker`_ that crawls the content to eventually throw out
88125Tagging
89126~~~~~~~
90127
91- Add the following to your Varnish configuration to enable :ref: `cache tagging <tags >`.
128+ If you have included fos_ban.vcl, tagging will be automatically enabled using a `` X-Cache-Tags `` header :ref: `cache tagging <tags >`.
92129
93130.. note ::
94-
95- The custom ``X-Cache-Tags `` header should match the tagging header
96- :ref: `configured in the cache invalidator <custom_tags_header >`.
131+ If you need to use a different tag for the headers than the default ``X-Cache-Tags `` used in ``fos_ban.vcl ``,
132+ you need to write your own VCL code and change the tagging header :ref: `configured in the cache invalidator <custom_tags_header >`.
97133
98134.. configuration-block ::
99135
100- .. literalinclude :: ../tests/Functional/Fixtures/ varnish-4/ban .vcl
136+ .. literalinclude :: ../resources/config/ varnish-4/fos_ban .vcl
101137 :language: varnish4
102- :emphasize-lines: 8-13,39
138+ :emphasize-lines: 8-13,40-41
103139 :linenos:
104140
105- .. literalinclude :: ../tests/Functional/Fixtures/ varnish-3/ban .vcl
141+ .. literalinclude :: ../resources/config/ varnish-3/fos_ban .vcl
106142 :language: varnish3
107- :emphasize-lines: 8-13,39
143+ :emphasize-lines: 8-13,40-41
108144 :linenos:
109145
110146.. _varnish user context :
@@ -115,17 +151,22 @@ User Context
115151To support :doc: `user context hashing <user-context >` you need to add some logic
116152to the ``recv `` and the ``deliver `` methods:
117153
118- .. configuration-block ::
154+ Subroutines are provided in ``fos_user_context.vcl ``.
155+
156+ To enable support add the following to ``your_varnish.vcl ``:
119157
158+ .. code-block :: varnish3
159+
160+ include "path-to-config/varnish-[version]/fos_user_context.vcl";
161+
162+ .. configuration-block ::
120163 .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/user_context.vcl
121164 :language: varnish4
122- :lines: 3-29, 33-
123- :linenos:
165+ :lines: 3-
124166
125167 .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/user_context.vcl
126168 :language: varnish3
127- :lines: 1-27, 31-
128- :linenos:
169+ :lines: 3-
129170
130171.. sidebar :: Caching User Specific Content
131172
@@ -205,15 +246,22 @@ Configure your Varnish to set a custom header (`X-Cache`) that shows whether a
205246cache hit or miss occurred. This header will only be set if your application
206247sends an `X-Cache-Debug ` header:
207248
208- .. configuration-block ::
249+ Subroutines are provided in ``fos_debug.vcl ``.
250+
251+ To enable support add the following to ``your_varnish.vcl ``:
252+
253+ .. code-block :: varnish3
254+
255+ include "path-to-config/varnish-[version]/fos_debug.vcl";
209256
210- .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/debug.vcl
257+ .. configuration-block ::
258+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/user_context.vcl
211259 :language: varnish4
212- :linenos:
260+ :lines: 12,13,15
213261
214- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/debug .vcl
262+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/user_context .vcl
215263 :language: varnish3
216- :linenos:
264+ :lines: 12,13,15
217265
218266.. _`builtin VCL` : https://www.varnish-cache.org/trac/browser/bin/varnishd/builtin.vcl?rev=4.0
219267.. _`default VCL` : https://www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0
0 commit comments