Fixed #26566 -- Rewrote an incorrect Cache-Control example.
This commit is contained in:
parent
8b2fce0f70
commit
101dd787ec
|
@ -1177,45 +1177,34 @@ decorator)::
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
There are a few other ways to control cache parameters. For example, HTTP
|
You can control downstream caches in other ways as well (see :rfc:`7234` for
|
||||||
allows applications to do the following:
|
details on HTTP caching). For example, even if you don't use Django's
|
||||||
|
server-side cache framework, you can still tell clients to cache a view for a
|
||||||
* Define the maximum time a page should be cached.
|
certain amount of time with the :rfc:`max-age <7234#section-5.2.2.8>`
|
||||||
|
directive::
|
||||||
* Specify whether a cache should always check for newer versions, only
|
|
||||||
delivering the cached content when there are no changes. (Some caches
|
|
||||||
might deliver cached content even if the server page changed, simply
|
|
||||||
because the cache copy isn't yet expired.)
|
|
||||||
|
|
||||||
In Django, use the ``cache_control`` view decorator to specify these cache
|
|
||||||
parameters. In this example, ``cache_control`` tells caches to revalidate the
|
|
||||||
cache on every access and to store cached versions for, at most, 3,600 seconds::
|
|
||||||
|
|
||||||
from django.views.decorators.cache import cache_control
|
from django.views.decorators.cache import cache_control
|
||||||
|
|
||||||
@cache_control(must_revalidate=True, max_age=3600)
|
@cache_control(max_age=3600)
|
||||||
def my_view(request):
|
def my_view(request):
|
||||||
...
|
...
|
||||||
|
|
||||||
Any valid ``Cache-Control`` HTTP directive is valid in ``cache_control()``.
|
(If you *do* use the caching middleware, it already sets the ``max-age`` with
|
||||||
Here's a full list:
|
the value of the :setting:`CACHE_MIDDLEWARE_SECONDS` setting. In that case,
|
||||||
|
the custom ``max_age`` from the ``cache_control`` decorator will take
|
||||||
|
precedence, and the header values will be merged correctly.)
|
||||||
|
|
||||||
|
Any valid ``Cache-Control`` response directive is valid in ``cache_control()``.
|
||||||
|
Here are some more examples:
|
||||||
|
|
||||||
* ``public=True``
|
|
||||||
* ``private=True``
|
|
||||||
* ``no_cache=True``
|
|
||||||
* ``no_transform=True``
|
* ``no_transform=True``
|
||||||
* ``must_revalidate=True``
|
* ``must_revalidate=True``
|
||||||
* ``proxy_revalidate=True``
|
* ``stale_while_revalidate=num_seconds``
|
||||||
* ``max_age=num_seconds``
|
|
||||||
* ``s_maxage=num_seconds``
|
|
||||||
|
|
||||||
For explanation of Cache-Control HTTP directives, see the :rfc:`Cache-Control
|
The full list of known directives can be found in the `IANA registry`_
|
||||||
spec <7234#section-5.2>`.
|
(note that not all of them apply to responses).
|
||||||
|
|
||||||
(Note that the caching middleware already sets the cache header's max-age with
|
.. _IANA registry: http://www.iana.org/assignments/http-cache-directives/http-cache-directives.xhtml
|
||||||
the value of the :setting:`CACHE_MIDDLEWARE_SECONDS` setting. If you use a custom
|
|
||||||
``max_age`` in a ``cache_control`` decorator, the decorator will take
|
|
||||||
precedence, and the header values will be merged correctly.)
|
|
||||||
|
|
||||||
If you want to use headers to disable caching altogether,
|
If you want to use headers to disable caching altogether,
|
||||||
:func:`django.views.decorators.cache.never_cache` is a view decorator that adds
|
:func:`django.views.decorators.cache.never_cache` is a view decorator that adds
|
||||||
|
|
Loading…
Reference in New Issue