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
{% load cache %}
near the top of your template. The {% cache %}
template tag caches the contents of the block for a given amount of time.
It takes at least two arguments: the cache timeout, in seconds, and the name to give the cache fragment. The name will be taken as is, do not use a variable.
For example:
{% load cache %} {% cache 500 sidebar %} .. sidebar .. {% 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 might want a separate cached copy of the sidebar used in the previous example for every user 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...