@@ -7,7 +7,7 @@ parameters described in the ``match`` section, the headers as defined under
77checked in the order specified, where the first match wins.
88
99A global setting and a per rule ``overwrite `` option allow to overwrite the
10- cache headers even if they are already set.
10+ cache headers even if they are already set:
1111
1212.. code-block :: yaml
1313
@@ -27,7 +27,7 @@ cache headers even if they are already set.
2727 public : false
2828 max_age : 0
2929 s_maxage : 0
30- last_modified : " -1 hour "
30+ etag : true
3131 vary : [Accept-Encoding, Accept-Language]
3232
3333 # match all actions of a specific controller
@@ -50,7 +50,7 @@ cache headers even if they are already set.
5050 public : true
5151 max_age : 64000
5252 s_maxage : 64000
53- last_modified : " -1 hour "
53+ etag : true
5454 vary : [Accept-Encoding, Accept-Language]
5555
5656 # match everything to set defaults
@@ -62,7 +62,7 @@ cache headers even if they are already set.
6262 public : true
6363 max_age : 15
6464 s_maxage : 30
65- last_modified : " -1 hour "
65+ etag : true
6666
6767 ``rules ``
6868---------
@@ -143,7 +143,7 @@ You can use the standard cache control directives:
143143* ``s_maxage `` time in seconds for proxy caches (also public caches);
144144* ``private `` true or false;
145145* ``public `` true or false;
146- * ``no_cache `` true or false (use exclusively to support HTTP 1.0);
146+ * ``no_cache `` true or false (use exclusively to support HTTP 1.0).
147147
148148.. code-block :: yaml
149149
@@ -166,23 +166,24 @@ default. If you want it respected, add your own logic to ``vcl_fetch``.
166166
167167.. note ::
168168
169- The cache-control headers are described in detail in :rfc: `2616#section-14.9 `.
169+ The cache-control headers are described in detail in :rfc: `2616#section-14.9 `
170+ and further clarified in :rfc: `7234#section-5.2 `.
170171
171172Extra Cache Control Directives
172173""""""""""""""""""""""""""""""
173174
174175You can also set headers that Symfony considers non-standard, some coming from
175- RFCs extending HTTP/1.1. The following options are supported:
176+ RFCs extending :rfc: ` 2616 ` HTTP/1.1. The following options are supported:
176177
177- * ``must_revalidate `` (:rfc: `2616 #section-14.9 `)
178- * ``proxy_revalidate `` (:rfc: `2616 #section-14.9 `)
179- * ``no_transform `` (:rfc: `2616 #section-14.9 `)
180- * ``stale_if_error ``: seconds (:rfc: `5861 `)
181- * ``stale_while_revalidate ``: seconds (:rfc: `5861 `)
178+ * ``must_revalidate `` (:rfc: `7234 #section-5.2.2.1 `)
179+ * ``proxy_revalidate `` (:rfc: `7234 #section-5.2.2.7 `)
180+ * ``no_transform `` (:rfc: `7234 #section-5.2.2.4 `)
181+ * ``stale_if_error ``: seconds (:rfc: `5861#section-4 `)
182+ * ``stale_while_revalidate ``: seconds (:rfc: `5861#section-3 `)
182183
183184The *stale * directives need a parameter specifying the time in seconds how long
184185a cache is allowed to continue serving stale content if needed. The other
185- directives are flags that are included when set to true.
186+ directives are flags that are included when set to true:
186187
187188.. code-block :: yaml
188189
@@ -200,13 +201,46 @@ directives are flags that are included when set to true.
200201 proxy_revalidate : true
201202 no_transform : true
202203
204+ ``etag ``
205+ """"""""
206+
207+ **type **: ``boolean ``
208+
209+ This enables a simplistic ETag calculated as md5 hash of the response body:
210+
211+ .. code-block :: yaml
212+
213+ # app/config/config.yml
214+ fos_http_cache :
215+ cache_control :
216+ rules :
217+ -
218+ headers :
219+ etag : true
220+
221+ .. tip ::
222+
223+ This simplistic ETag handler will not help you to prevent unnecessary work
224+ on your web server, but allows a caching proxy to use the ETag cache
225+ validation method to preserve bandwidth. The presence of an ETag tells
226+ clients that they can send a ``If-None-Match `` header with the ETag their
227+ current version of the content has. If the caching proxy still has the same
228+ ETag, it responds with a "304 Not Modified" status.
229+
230+ You can get additional performance if you write your own ETag handler that
231+ can read an ETag from your content and decide very early in the request
232+ whether the ETag changed or not. It can then terminate the request early
233+ with an empty "304 Not Modified" response. This avoids rendering the whole
234+ page. If the page depends on permissions, make sure to make the ETag differ
235+ based on those permissions (e.g. by appending the :doc: `user context hash </features/user-context >`).
236+
203237``last_modified ``
204238"""""""""""""""""
205239
206240**type **: ``string ``
207241
208242The input to the ``last_modified `` is used for the ``Last-Modified `` header.
209- This value must be a valid input to ``DateTime ``.
243+ This value must be a valid input to ``DateTime ``:
210244
211245.. code-block :: yaml
212246
@@ -218,20 +252,36 @@ This value must be a valid input to ``DateTime``.
218252 headers :
219253 last_modified : " -1 hour"
220254
221- .. hint ::
255+ .. note ::
222256
223257 Setting an arbitrary last modified time allows clients to send
224258 ``If-Modified-Since `` requests. Varnish can handle these to serve data
225259 from the cache if it was not invalidated since the client requested it.
226260
261+ Note that the default system will generate an arbitrary last modified date.
262+ You can get additional performance if you write your own last modified
263+ handler that can compare this date with information about the content of
264+ your page and decide early in the request whether anything changed. It can
265+ then terminate the request early with an empty "304 Not Modified" response.
266+ Using content meta data increases the probability for a 304 response and
267+ avoids rendering the whole page.
268+
269+ See also :rfc: `7232#section-2.2.1 ` for further consideration on how to
270+ generate the last modified date.
271+
272+ .. note ::
273+
274+ You may configure both ETag and last modified on the same response. See
275+ :rfc: `7232#section-2.4 ` for more details.
276+
227277``vary ``
228278""""""""
229279
230280**type **: ``string ``
231281
232282You can set the `vary ` option to an array that defines the contents of the
233283`Vary ` header when matching the request. This adds to existing Vary headers,
234- keeping previously set Vary options.
284+ keeping previously set Vary options:
235285
236286.. code-block :: yaml
237287
0 commit comments