@@ -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
@@ -182,7 +182,7 @@ RFCs extending HTTP/1.1. The following options are supported:
182182
183183The *stale * directives need a parameter specifying the time in seconds how long
184184a cache is allowed to continue serving stale content if needed. The other
185- directives are flags that are included when set to true.
185+ directives are flags that are included when set to true:
186186
187187.. code-block :: yaml
188188
@@ -200,13 +200,44 @@ directives are flags that are included when set to true.
200200 proxy_revalidate : true
201201 no_transform : true
202202
203+ ``etag ``
204+ """"""""
205+
206+ **type **: ``boolean ``
207+
208+ This enables a simplistic ETag calculated as md5 hash of the response body:
209+
210+ .. code-block :: yaml
211+
212+ # app/config/config.yml
213+ fos_http_cache :
214+ cache_control :
215+ rules :
216+ -
217+ headers :
218+ etag : true
219+
220+ .. tip ::
221+
222+ This simplistic ETag handler will not help you to prevent unnecessary work
223+ on your webserver, but allows a caching proxy to use the ETag cache
224+ validation method to preserve bandwidth. The presence of an ETag tells
225+ clients that they can send a ``If-None-Match `` header with the ETag their
226+ current version of the content has. If the caching proxy still has the same
227+ ETag, it responds with a "304 Not Modified" status.
228+
229+ You can get additional performance if you write your own ETag listener that
230+ also checks the ETag on requests and decides whether the content of the
231+ requested page would still generate the same ETag and abort the request as
232+ early as possible to return the "304 Not Modified" status.
233+
203234``last_modified ``
204235"""""""""""""""""
205236
206237**type **: ``string ``
207238
208239The input to the ``last_modified `` is used for the ``Last-Modified `` header.
209- This value must be a valid input to ``DateTime ``.
240+ This value must be a valid input to ``DateTime ``:
210241
211242.. code-block :: yaml
212243
@@ -218,20 +249,30 @@ This value must be a valid input to ``DateTime``.
218249 headers :
219250 last_modified : " -1 hour"
220251
221- .. hint ::
252+ .. note ::
222253
223254 Setting an arbitrary last modified time allows clients to send
224255 ``If-Modified-Since `` requests. Varnish can handle these to serve data
225256 from the cache if it was not invalidated since the client requested it.
226257
258+ If you only use these simple configurations to add cache validation
259+ information, there is no point in adding both a last modified and ETag
260+ header. Usually, you should prefer the ETag method as it is not prone to
261+ clock skew issues.
262+
263+ If your site is under heavy load, your best option is to write either a
264+ custom ETag handler or a custom last modified handler that uses the content
265+ of the page in a way that can avoid rendering the whole page before
266+ deciding whether the cached version is still valid.
267+
227268``vary ``
228269""""""""
229270
230271**type **: ``string ``
231272
232273You can set the `vary ` option to an array that defines the contents of the
233274`Vary ` header when matching the request. This adds to existing Vary headers,
234- keeping previously set Vary options.
275+ keeping previously set Vary options:
235276
236277.. code-block :: yaml
237278
0 commit comments