@@ -166,19 +166,20 @@ default. If you want it respected, add your own logic to ``vcl_fetch``.
166
166
167
167
.. note ::
168
168
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 `.
170
171
171
172
Extra Cache Control Directives
172
173
""""""""""""""""""""""""""""""
173
174
174
175
You 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:
176
177
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 `)
182
183
183
184
The *stale * directives need a parameter specifying the time in seconds how long
184
185
a cache is allowed to continue serving stale content if needed. The other
@@ -220,16 +221,18 @@ This enables a simplistic ETag calculated as md5 hash of the response body:
220
221
.. tip ::
221
222
222
223
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
+ on your web server , but allows a caching proxy to use the ETag cache
224
225
validation method to preserve bandwidth. The presence of an ETag tells
225
226
clients that they can send a ``If-None-Match `` header with the ETag their
226
227
current version of the content has. If the caching proxy still has the same
227
228
ETag, it responds with a "304 Not Modified" status.
228
229
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.
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 >`).
233
236
234
237
``last_modified ``
235
238
"""""""""""""""""
@@ -255,15 +258,21 @@ This value must be a valid input to ``DateTime``:
255
258
``If-Modified-Since `` requests. Varnish can handle these to serve data
256
259
from the cache if it was not invalidated since the client requested it.
257
260
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.
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.
262
268
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.
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.
267
276
268
277
``vary ``
269
278
""""""""
0 commit comments