@@ -3,7 +3,8 @@ cache_control
3
3
4
4
The configuration contains a number of *rules *. When a request matches the
5
5
parameters described in the ``match `` section, the headers as defined under
6
- ``headers `` will be set on the response, if they are not already set.
6
+ ``headers `` will be set on the response, if they are not already set. Rules are
7
+ checked in the order specified, where the first match wins.
7
8
8
9
.. code-block :: yaml
9
10
@@ -16,7 +17,11 @@ parameters described in the ``match`` section, the headers as defined under
16
17
match :
17
18
host : ^login.example.com$
18
19
headers :
19
- cache_control : { public: false, max_age: 0, s_maxage: 0, last_modified: "-1 hour" }
20
+ cache_control :
21
+ public : false
22
+ max_age : 0
23
+ s_maxage : 0
24
+ last_modified : " -1 hour"
20
25
vary : [Accept-Encoding, Accept-Language]
21
26
22
27
# match all actions of a specific controller
@@ -25,52 +30,43 @@ parameters described in the ``match`` section, the headers as defined under
25
30
attributes : { _controller: ^AcmeBundle:Default:.* }
26
31
additional_cacheable_status : [400]
27
32
headers :
28
- cache_control : { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
33
+ cache_control :
34
+ public : true
35
+ max_age : 15
36
+ s_maxage : 30
37
+ last_modified : " -1 hour"
29
38
30
39
-
31
40
match :
32
41
path : ^/$
33
42
headers :
34
- cache_control : { public: true, max_age: 64000, s_maxage: 64000, last_modified: "-1 hour" }
43
+ cache_control :
44
+ public : true
45
+ max_age : 64000
46
+ s_maxage : 64000
47
+ last_modified : " -1 hour"
35
48
vary : [Accept-Encoding, Accept-Language]
36
49
37
50
# match everything to set defaults
38
51
-
39
52
match :
40
53
path : ^/
41
54
headers :
42
- cache_control : { public: true, max_age: 15, s_maxage: 30, last_modified: "-1 hour" }
55
+ cache_control :
56
+ public : true
57
+ max_age : 15
58
+ s_maxage : 30
59
+ last_modified : " -1 hour"
43
60
44
61
rules
45
62
-----
46
63
47
64
**type **: ``array ``
48
65
49
- A set of cache control rules.
66
+ A set of cache control rules consisting of * match * criteria and * header * instructions .
50
67
51
68
.. include :: /includes/match.rst
52
69
53
- .. sidebar :: Merging headers
54
-
55
- If the response already has certain cache directives set, they are not
56
- overwritten. The configuration can thus specify defaults that may be
57
- changed by controllers or services that handle the response, or ``@Cache ``
58
- annotations.
59
-
60
- The listener that applies the rules is triggered at priority 10, which
61
- makes it handle before the ``@Cache `` annotations from the
62
- SensioFrameworkExtraBundle are evaluated. Those annotations unconditionally
63
- overwrite cache directives.
64
-
65
- The only exception is responses that *only * have the ``no-cache ``
66
- directive. This is the default value for the cache control and there is no
67
- way to determine if it was manually set. If the full header is only
68
- ``no-cache ``, the whole cache control is overwritten.
69
-
70
- You can prevent the cache control on specific requests by injecting the
71
- service ``fos_http_cache.event_listener.cache_control `` and calling
72
- ``setSkip() `` on it. If this method is called, no cache rules are applied.
73
-
74
70
headers
75
71
^^^^^^^
76
72
@@ -107,6 +103,25 @@ headers
107
103
In the ``headers `` section, you define what headers to set on the response if
108
104
the request was matched.
109
105
106
+ Headers are **merged **. If the response already has certain cache directives
107
+ set, they are not overwritten. The configuration can thus specify defaults
108
+ that may be changed by controllers or services that handle the response, or
109
+ ``@Cache `` annotations.
110
+
111
+ The listener that applies the rules is triggered at priority 10, which
112
+ makes it handle before the ``@Cache `` annotations from the
113
+ SensioFrameworkExtraBundle are evaluated. Those annotations unconditionally
114
+ overwrite cache directives.
115
+
116
+ The only exception is responses that *only * have the ``no-cache ``
117
+ directive. This is the default value for the cache control and there is no
118
+ way to determine if it was manually set. If the full header is only
119
+ ``no-cache ``, the whole cache control is overwritten.
120
+
121
+ You can prevent the cache control on specific requests by injecting the
122
+ service ``fos_http_cache.event_listener.cache_control `` and calling
123
+ ``setSkip() `` on it. If this method is called, no cache rules are applied.
124
+
110
125
cache_control
111
126
"""""""""""""
112
127
@@ -227,7 +242,7 @@ reverse_proxy_ttl
227
242
228
243
**type **: ``integer ``
229
244
230
- For X-Reverse-Proxy-TTL for Custom Reverse Proxy Time-Outs
245
+ Set a X-Reverse-Proxy-TTL header for reverse proxy time-outs not driven by `` s-maxage ``.
231
246
232
247
By default, reverse proxies use the ``s-maxage `` of your ``Cache-Control `` header
233
248
to know how long it should cache a page. But by default, the s-maxage is also
@@ -255,7 +270,9 @@ then use on the reverse proxy:
255
270
-
256
271
headers :
257
272
reverse_proxy_ttl : 3600
258
- cache_control : { public: true, s_maxage: 60 }
273
+ cache_control :
274
+ public : true
275
+ s_maxage : 60
259
276
260
277
This example adds the header ``X-Reverse-Proxy-TTL: 3600 `` to your responses.
261
278
Varnish by default knows nothing about this header. To make this solution work,
0 commit comments