@@ -33,22 +33,41 @@ will be used throughout the Varnish examples on this page.
33
33
trigger invalidation are whitelisted here. Otherwise, lost cache invalidation
34
34
requests will lead to lots of confusion.
35
35
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
+
36
49
Purge
37
50
~~~~~
38
51
39
52
To configure Varnish for `handling PURGE requests <https://www.varnish-cache.org/docs/3.0/tutorial/purging.html >`_:
40
53
41
54
Purge removes a specific URL (including query strings) in all its variants (as specified by the ``Vary `` header).
42
55
43
- .. configuration-block ::
56
+ Subroutines are provided in `` resources/config/varnis-[version]/fos_purge.vcl ``.
44
57
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
48
61
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
50
69
:language: varnish3
51
- :linenos:
70
+ :lines: 15,17,19-20,25-32
52
71
53
72
Refresh
54
73
~~~~~~~
@@ -58,26 +77,44 @@ add the following to your Varnish configuration:
58
77
59
78
Refresh invalidates a specific URL including the query string, but *not * its variants.
60
79
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
64
96
65
97
Ban
66
98
~~~
67
99
68
100
To configure Varnish for `handling BAN requests <https://www.varnish-software.com/static/book/Cache_invalidation.html#banning >`_:
69
101
70
- .. configuration-block ::
102
+ Subroutines are provided in `` fos_ban.vcl ``
71
103
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
73
112
:language: varnish4
74
- :lines: 1-7, 15-18, 20-
75
- :linenos:
113
+ :lines: 17-18,21-29
76
114
77
- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/ban .vcl
115
+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/fos .vcl
78
116
:language: varnish3
79
- :lines: 1-7, 15-18, 20-
80
- :linenos:
117
+ :lines: 15-16,19-24,33-35
81
118
82
119
Varnish contains a `ban lurker `_ that crawls the content to eventually throw out banned data even when it’s not requested by any client.
83
120
@@ -88,23 +125,22 @@ Varnish contains a `ban lurker`_ that crawls the content to eventually throw out
88
125
Tagging
89
126
~~~~~~~
90
127
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 >`.
92
129
93
130
.. 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 >`.
97
133
98
134
.. configuration-block ::
99
135
100
- .. literalinclude :: ../tests/Functional/Fixtures/ varnish-4/ban .vcl
136
+ .. literalinclude :: ../resources/config/ varnish-4/fos_ban .vcl
101
137
:language: varnish4
102
- :emphasize-lines: 8-13,39
138
+ :emphasize-lines: 8-13,40-41
103
139
:linenos:
104
140
105
- .. literalinclude :: ../tests/Functional/Fixtures/ varnish-3/ban .vcl
141
+ .. literalinclude :: ../resources/config/ varnish-3/fos_ban .vcl
106
142
:language: varnish3
107
- :emphasize-lines: 8-13,39
143
+ :emphasize-lines: 8-13,40-41
108
144
:linenos:
109
145
110
146
.. _varnish user context :
@@ -115,17 +151,22 @@ User Context
115
151
To support :doc: `user context hashing <user-context >` you need to add some logic
116
152
to the ``recv `` and the ``deliver `` methods:
117
153
118
- .. configuration-block ::
154
+ Subroutines are provided in ``fos_user_context.vcl ``.
155
+
156
+ To enable support add the following to ``your_varnish.vcl ``:
119
157
158
+ .. code-block :: varnish3
159
+
160
+ include "path-to-config/varnish-[version]/fos_user_context.vcl";
161
+
162
+ .. configuration-block ::
120
163
.. literalinclude :: ../tests/Functional/Fixtures/varnish-4/user_context.vcl
121
164
:language: varnish4
122
- :lines: 3-29, 33-
123
- :linenos:
165
+ :lines: 3-
124
166
125
167
.. literalinclude :: ../tests/Functional/Fixtures/varnish-3/user_context.vcl
126
168
:language: varnish3
127
- :lines: 1-27, 31-
128
- :linenos:
169
+ :lines: 3-
129
170
130
171
.. sidebar :: Caching User Specific Content
131
172
@@ -205,15 +246,22 @@ Configure your Varnish to set a custom header (`X-Cache`) that shows whether a
205
246
cache hit or miss occurred. This header will only be set if your application
206
247
sends an `X-Cache-Debug ` header:
207
248
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";
209
256
210
- .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/debug.vcl
257
+ .. configuration-block ::
258
+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-4/user_context.vcl
211
259
:language: varnish4
212
- :linenos:
260
+ :lines: 12,13,15
213
261
214
- .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/debug .vcl
262
+ .. literalinclude :: ../tests/Functional/Fixtures/varnish-3/user_context .vcl
215
263
:language: varnish3
216
- :linenos:
264
+ :lines: 12,13,15
217
265
218
266
.. _`builtin VCL` : https://www.varnish-cache.org/trac/browser/bin/varnishd/builtin.vcl?rev=4.0
219
267
.. _`default VCL` : https://www.varnish-cache.org/trac/browser/bin/varnishd/default.vcl?rev=3.0
0 commit comments