Ticket #1065: fragment_caching_docs.diff

File fragment_caching_docs.diff, 1.6 KB (added by nick.lane.au@…, 18 years ago)

Added docs

  • docs/cache.txt

    === modified file 'docs/cache.txt'
     
    277277above example, the result of the ``slashdot_this()`` view will be cached for 15
    278278minutes.
    279279
     280Fragment caching
     281================
     282
     283If you're after even more control, you can also easily cache template fragments
     284using the ``cache`` template tag. To give your template access to this tag, put
     285``{% load fragment_caching %}`` near the top of your template.
     286
     287The ``{% cache %}`` template tag caches the contents of the block for a given
     288amount of time and takes at least two arguments. The first argument is the
     289cache timeout, in seconds. The second argument is the name to give the cache
     290fragment. For example::
     291
     292    {% load fragment_caching %}
     293    {% cache 500 sidebar %}
     294        .. sidebar ..
     295    {% endcache %}
     296
     297Sometimes you might want to cache multiple copies of a fragment depending on
     298some dynamic data that appears inside the fragment. For example you may want a
     299separate cached copy of the sidebar used in the previous example for every user
     300of your site. This can be easily achieved by passing additional arguments to
     301the ``{% cache %}`` template tag to uniquely identify the cache fragment::
     302
     303    {% load fragment_caching %}
     304    {% cache 500 sidebar request.user.username %}
     305        .. sidebar for logged in user ..
     306    {% endcache %}
     307
     308If you need more than one argument to identify the fragment that's fine, simply
     309pass as many arguments to ``{% cache %}`` as you need!
     310
    280311The low-level cache API
    281312=======================
    282313
Back to Top