Ticket #14738: link-settings-in-cache-docs.diff

File link-settings-in-cache-docs.diff, 13.1 KB (added by Adam Vandenberg, 14 years ago)
  • docs/ref/settings.txt

    diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
    index 87219b2..b551a27 100644
    a b caches every page that doesn't have GET or POST parameters.  
    169169If you set the value of this setting to ``True``, you should make sure you've
    170170activated ``AuthenticationMiddleware``.
    171171
    172 See the :doc:`cache documentation </topics/cache>` for more information.
     172See :doc:`/topics/cache`.
    173173
    174174.. setting:: CACHE_MIDDLEWARE_KEY_PREFIX
    175175
    CACHE_MIDDLEWARE_KEY_PREFIX  
    178178
    179179Default: ``''`` (Empty string)
    180180
    181 The cache key prefix that the cache middleware should use. See
    182 :doc:`/topics/cache`.
     181The cache key prefix that the cache middleware should use.
     182
     183See :doc:`/topics/cache`.
    183184
    184185.. setting:: CACHE_MIDDLEWARE_SECONDS
    185186
    Default: ``600``  
    191192The default number of seconds to cache a page when the caching middleware or
    192193``cache_page()`` decorator is used.
    193194
     195See :doc:`/topics/cache`.
     196
    194197.. setting:: CACHE_PREFIX
    195198
    196199CACHE_PREFIX
  • docs/topics/cache.txt

    diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt
    index a98762f..b3aa4a8 100644
    a b explaining how this would work for a dynamically generated Web page::  
    3131Django comes with a robust cache system that lets you save dynamic pages so
    3232they don't have to be calculated for each request. For convenience, Django
    3333offers different levels of cache granularity: You can cache the output of
    34 specific views, you can cache only the pieces that are difficult to produce, or
    35 you can cache your entire site.
     34specific views, you can cache only the pieces that are difficult to produce,
     35or you can cache your entire site.
    3636
    3737Django also works well with "upstream" caches, such as Squid
    3838(http://www.squid-cache.org/) and browser-based caches. These are the types of
    where your cached data should live -- whether in a database, on the filesystem  
    4747or directly in memory. This is an important decision that affects your cache's
    4848performance; yes, some cache types are faster than others.
    4949
    50 Your cache preference goes in the ``CACHE_BACKEND`` setting in your settings
    51 file. Here's an explanation of all available values for ``CACHE_BACKEND``.
     50Your cache preference goes in the :setting:`CACHE_BACKEND` setting in your
     51settings file. Here's an explanation of all available values for
     52:setting:`CACHE_BACKEND`.
    5253
    5354Memcached
    5455---------
    This is available at ftp://ftp.tummy.com/pub/python-memcached/  
    7576    a lack of maintenance on the ``cmemcache`` library itself. Support for
    7677    ``cmemcache`` will be removed completely in Django 1.4.
    7778
    78 To use Memcached with Django, set ``CACHE_BACKEND`` to
     79To use Memcached with Django, set :setting:`CACHE_BACKEND` to
    7980``memcached://ip:port/``, where ``ip`` is the IP address of the Memcached
    8081daemon and ``port`` is the port on which Memcached is running.
    8182
    One excellent feature of Memcached is its ability to share cache over multiple  
    8788servers. This means you can run Memcached daemons on multiple machines, and the
    8889program will treat the group of machines as a *single* cache, without the need
    8990to duplicate cache values on each machine. To take advantage of this feature,
    90 include all server addresses in ``CACHE_BACKEND``, separated by semicolons.
     91include all server addresses in :setting:`CACHE_BACKEND`, separated by
     92semicolons.
    9193
    9294In this example, the cache is shared over Memcached instances running on IP
    9395address 172.19.26.240 and 172.19.26.242, both on port 11211::
    not already being used in your database.) This command creates a single table  
    123125in your database that is in the proper format that Django's database-cache
    124126system expects.
    125127
    126 Once you've created that database table, set your ``CACHE_BACKEND`` setting to
    127 ``"db://tablename"``, where ``tablename`` is the name of the database table.
    128 In this example, the cache table's name is ``my_cache_table``::
     128Once you've created that database table, set your :setting:`CACHE_BACKEND`
     129setting to ``"db://tablename"``, where ``tablename`` is the name of the
     130database table. In this example, the cache table's name is
     131``my_cache_table``::
    129132
    130133    CACHE_BACKEND = 'db://my_cache_table'
    131134
    Filesystem caching  
    181184------------------
    182185
    183186To store cached items on a filesystem, use the ``"file://"`` cache type for
    184 ``CACHE_BACKEND``. For example, to store cached data in ``/var/tmp/django_cache``,
    185 use this setting::
     187:setting:`CACHE_BACKEND`. For example, to store cached data in
     188``/var/tmp/django_cache``, use this setting::
    186189
    187190    CACHE_BACKEND = 'file:///var/tmp/django_cache'
    188191
    Local-memory caching  
    212215
    213216If you want the speed advantages of in-memory caching but don't have the
    214217capability of running Memcached, consider the local-memory cache backend. This
    215 cache is multi-process and thread-safe. To use it, set ``CACHE_BACKEND`` to
    216 ``"locmem://"``. For example::
     218cache is multi-process and thread-safe. To use it, set :setting:`CACHE_BACKEND`
     219to ``"locmem://"``. For example::
    217220
    218221    CACHE_BACKEND = 'locmem://'
    219222
    just implements the cache interface without doing anything.  
    231234This is useful if you have a production site that uses heavy-duty caching in
    232235various places but a development/test environment where you don't want to cache
    233236and don't want to have to change your code to special-case the latter. To
    234 activate dummy caching, set ``CACHE_BACKEND`` like so::
     237activate dummy caching, set :setting:`CACHE_BACKEND` like so::
    235238
    236239    CACHE_BACKEND = 'dummy://'
    237240
    Using a custom cache backend  
    243246While Django includes support for a number of cache backends out-of-the-box,
    244247sometimes you might want to use a customized cache backend. To use an external
    245248cache backend with Django, use a Python import path as the scheme portion (the
    246 part before the initial colon) of the ``CACHE_BACKEND`` URI, like so::
     249part before the initial colon) of the :setting:`CACHE_BACKEND` URI, like so::
    247250
    248251    CACHE_BACKEND = 'path.to.backend://'
    249252
    CACHE_BACKEND arguments  
    259262-----------------------
    260263
    261264Each cache backend may take arguments. They're given in query-string style on
    262 the ``CACHE_BACKEND`` setting. Valid arguments are as follows:
     265the :setting:`CACHE_BACKEND` setting. Valid arguments are as follows:
    263266
    264267    * ``timeout``: The default timeout, in seconds, to use for the cache.
    265268      This argument defaults to 300 seconds (5 minutes).
    entire site. You'll need to add  
    315318
    316319Then, add the following required settings to your Django settings file:
    317320
    318 * ``CACHE_MIDDLEWARE_SECONDS`` -- The number of seconds each page should be
    319   cached.
    320 * ``CACHE_MIDDLEWARE_KEY_PREFIX`` -- If the cache is shared across multiple
    321   sites using the same Django installation, set this to the name of the site,
    322   or some other string that is unique to this Django instance, to prevent key
    323   collisions. Use an empty string if you don't care.
     321* :setting:`CACHE_MIDDLEWARE_SECONDS` -- The number of seconds each page should
     322  be cached.
     323* :setting:`CACHE_MIDDLEWARE_KEY_PREFIX` -- If the cache is shared across
     324  multiple sites using the same Django installation, set this to the name of
     325  the site, or some other string that is unique to this Django instance, to
     326  prevent key collisions. Use an empty string if you don't care.
    324327
    325328The cache middleware caches every page that doesn't have GET or POST
    326 parameters. Optionally, if the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is
    327 ``True``, only anonymous requests (i.e., not those made by a logged-in user)
    328 will be cached. This is a simple and effective way of disabling caching for any
    329 user-specific pages (include Django's admin interface). Note that if you use
    330 ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY``, you should make sure you've activated
    331 ``AuthenticationMiddleware``. The cache middleware expects that a HEAD request
    332 is answered with the same response headers exactly like the corresponding GET
    333 request, in that case it could return cached GET response for HEAD request.
     329parameters. Optionally, if the :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY`
     330setting is ``True``, only anonymous requests (i.e., not those made by a
     331logged-in user) will be cached. This is a simple and effective way of disabling
     332caching for any user-specific pages (include Django's admin interface). Note
     333that if you use :setting:`CACHE_MIDDLEWARE_ANONYMOUS_ONLY`, you should make
     334sure you've activated ``AuthenticationMiddleware``. The cache middleware
     335expects that a HEAD request is answered with the same response headers exactly
     336like the corresponding GET request, in that case it could return cached GET
     337response for HEAD request.
    334338
    335339Additionally, the cache middleware automatically sets a few headers in each
    336340``HttpResponse``:
    Additionally, the cache middleware automatically sets a few headers in each  
    339343      (uncached) version of the page is requested.
    340344
    341345    * Sets the ``Expires`` header to the current date/time plus the defined
    342       ``CACHE_MIDDLEWARE_SECONDS``.
     346      :setting:`CACHE_MIDDLEWARE_SECONDS`.
    343347
    344348    * Sets the ``Cache-Control`` header to give a max age for the page --
    345       again, from the ``CACHE_MIDDLEWARE_SECONDS`` setting.
     349      again, from the :setting:`CACHE_MIDDLEWARE_SECONDS` setting.
    346350
    347351See :doc:`/topics/http/middleware` for more on middleware.
    348352
    See :doc:`/topics/http/middleware` for more on middleware.  
    350354
    351355If a view sets its own cache expiry time (i.e. it has a ``max-age`` section in
    352356its ``Cache-Control`` header) then the page will be cached until the expiry
    353 time, rather than ``CACHE_MIDDLEWARE_SECONDS``. Using the decorators in
     357time, rather than :setting:`CACHE_MIDDLEWARE_SECONDS`. Using the decorators in
    354358``django.views.decorators.cache`` you can easily set a view's expiry time
    355359(using the ``cache_control`` decorator) or disable caching for a view (using
    356360the ``never_cache`` decorator). See the `using other headers`__ section for
    __ `Controlling cache: Using other headers`_  
    373377The per-view cache
    374378==================
    375379
     380.. function ``django.views.decorators.cache.cache_page``
     381
    376382A more granular way to use the caching framework is by caching the output of
    377383individual views. ``django.views.decorators.cache`` defines a ``cache_page``
    378384decorator that will automatically cache the view's response for you. It's easy
    then requests to ``/foo/1/`` and ``/foo/23/`` will be cached separately, as  
    402408you may expect. But once a particular URL (e.g., ``/foo/23/``) has been
    403409requested, subsequent requests to that URL will use the cache.
    404410
    405 ``cache_page`` can also take an optional keyword argument, ``key_prefix``, which
    406 works in the same way as the ``CACHE_MIDDLEWARE_KEY_PREFIX`` setting for the
    407 middleware.  It can be used like this::
     411``cache_page`` can also take an optional keyword argument, ``key_prefix``,
     412which works in the same way as the :setting:`CACHE_MIDDLEWARE_KEY_PREFIX`
     413setting for the middleware.  It can be used like this::
    408414
    409415    @cache_page(60 * 15, key_prefix="site1")
    410416    def my_view(request):
    can be pickled; refer to the Python documentation for more information about  
    529535pickling.)
    530536
    531537The cache module, ``django.core.cache``, has a ``cache`` object that's
    532 automatically created from the ``CACHE_BACKEND`` setting::
     538automatically created from the :setting:`CACHE_BACKEND` setting::
    533539
    534540    >>> from django.core.cache import cache
    535541
    The basic interface is ``set(key, value, timeout)`` and ``get(key)``::  
    540546    'hello, world!'
    541547
    542548The ``timeout`` argument is optional and defaults to the ``timeout``
    543 argument in the ``CACHE_BACKEND`` setting (explained above). It's the number of
    544 seconds the value should be stored in the cache.
     549argument in the :setting:`CACHE_BACKEND` setting (explained above). It's the
     550number of seconds the value should be stored in the cache.
    545551
    546552If the object doesn't exist in the cache, ``cache.get()`` returns ``None``::
    547553
    Here's a full list:  
    957963For explanation of Cache-Control HTTP directives, see the `Cache-Control spec`_.
    958964
    959965(Note that the caching middleware already sets the cache header's max-age with
    960 the value of the ``CACHE_MIDDLEWARE_SETTINGS`` setting. If you use a custom
     966the value of the :setting:`CACHE_MIDDLEWARE_SETTINGS` setting. If you use a custom
    961967``max_age`` in a ``cache_control`` decorator, the decorator will take
    962968precedence, and the header values will be merged correctly.)
    963969
    site's performance:  
    984990      modern browsers to conditionally GET responses based on the ``ETag``
    985991      and ``Last-Modified`` headers.
    986992
    987     * ``django.middleware.gzip.GZipMiddleware`` compresses responses for all
     993    * :class:`django.middleware.gzip.GZipMiddleware` compresses responses for all
    988994      moderns browsers, saving bandwidth and transfer time.
    989995
    990996Order of MIDDLEWARE_CLASSES
    991997===========================
    992998
    993999If you use caching middleware, it's important to put each half in the right
    994 place within the ``MIDDLEWARE_CLASSES`` setting. That's because the cache
     1000place within the :setting:`MIDDLEWARE_CLASSES` setting. That's because the cache
    9951001middleware needs to know which headers by which to vary the cache storage.
    9961002Middleware always adds something to the ``Vary`` response header when it can.
    9971003
Back to Top