diff options
| author | Jeremy Dunck <jdunck@gmail.com> | 2007-12-01 22:12:44 +0000 |
|---|---|---|
| committer | Jeremy Dunck <jdunck@gmail.com> | 2007-12-01 22:12:44 +0000 |
| commit | 23384af79b2f43f08e8395d0a84a57c2a98df392 (patch) | |
| tree | 77e45f0e0fc6cb9b3380982313f45febf2ebf6f0 /docs/cache.txt | |
| parent | 85ce45bc441e4ace2fba83bc2d2432e22ec9da94 (diff) | |
gis: Merged 6672-6783 vis svnmerge from trunk
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6815 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/cache.txt')
| -rw-r--r-- | docs/cache.txt | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/docs/cache.txt b/docs/cache.txt index 4f177b8c07..af6cb35c42 100644 --- a/docs/cache.txt +++ b/docs/cache.txt @@ -263,6 +263,18 @@ See the `middleware documentation`_ for more on middleware. .. _`middleware documentation`: ../middleware/ +**New in Django development version** + +If a view sets its own cache expiry time (i.e. it has a ``max-age`` section in +its ``Cache-Control`` header) then the page will be cached until the expiry +time, rather than ``CACHE_MIDDLEWARE_SECONDS``. Using the decorators in +``django.views.decorators.cache`` you can easily set a view's expiry time +(using the ``cache_control`` decorator) or disable caching for a view (using +the ``never_cache`` decorator). See the `using other headers`__ section for +more on these decorators. + +__ `Controlling cache: Using other headers`_ + The per-view cache ================== @@ -291,7 +303,7 @@ minutes. Template fragment caching ========================= -**New in development version**. +**New in development version** If you're after even more control, you can also cache template fragments using the ``cache`` template tag. To give your template access to this tag, put @@ -307,18 +319,18 @@ and the name to give the cache fragment. For example:: {% endcache %} Sometimes you might want to cache multiple copies of a fragment depending on -some dynamic data that appears inside the fragment. For example you may want a +some dynamic data that appears inside the fragment. For example, you might want a separate cached copy of the sidebar used in the previous example for every user -of your site. This can be easily achieved by passing additional arguments to -the ``{% cache %}`` template tag to uniquely identify the cache fragment:: +of your site. Do this by passing additional arguments to the ``{% cache %}`` +template tag to uniquely identify the cache fragment:: {% load cache %} {% cache 500 sidebar request.user.username %} .. sidebar for logged in user .. {% endcache %} -If you need more than one argument to identify the fragment that's fine, simply -pass as many arguments to ``{% cache %}`` as you need! +It's perfectly fine to specify more than one argument to identify the fragment. +Simply pass as many arguments to ``{% cache %}`` as you need. The low-level cache API ======================= @@ -358,16 +370,16 @@ get() can take a ``default`` argument:: >>> cache.get('my_key', 'has expired') 'has expired' -To add a key only if it doesn't already exist, there is an add() method. It -takes the same parameters as set(), but will not attempt to update the cache -if the key specified is already present:: +**New in Django development version:** To add a key only if it doesn't already +exist, use the ``add()`` method. It takes the same parameters as ``set()``, but +it will not attempt to update the cache if the key specified is already present:: >>> cache.set('add_key', 'Initial value') >>> cache.add('add_key', 'New value') >>> cache.get('add_key') 'Initial value' -There's also a get_many() interface that only hits the cache once. get_many() +There's also a ``get_many()`` interface that only hits the cache once. ``get_many()`` returns a dictionary with all the keys you asked for that actually exist in the cache (and haven't expired):: @@ -566,7 +578,7 @@ the value of the ``CACHE_MIDDLEWARE_SETTINGS`` setting. If you use a custom precedence, and the header values will be merged correctly.) If you want to use headers to disable caching altogether, -``django.views.decorators.never_cache`` is a view decorator that adds +``django.views.decorators.cache.never_cache`` is a view decorator that adds headers to ensure the response won't be cached by browsers or other caches. Example:: from django.views.decorators.cache import never_cache |
