diff options
| author | Tomek Paczkowski <tomek@hauru.eu> | 2013-02-24 12:58:02 +0100 |
|---|---|---|
| committer | Honza Kral <honza.kral@gmail.com> | 2013-02-24 14:32:45 +0100 |
| commit | 99edbe0e279166db82caaf545ef92d5446a6a07e (patch) | |
| tree | 495785ea6bca5f1c94881d624b622b1d6ea93b30 /docs/topics | |
| parent | b9cc61021a0db1e5b41e61d3e53180e4fc618f9c (diff) | |
Fixed #19253 -- Extracted template cache key building logic
Introduced a public function
django.core.cache.utils.make_template_fragment_key
Thanks @chrismedrela for fruitful cooperation.
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/cache.txt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/topics/cache.txt b/docs/topics/cache.txt index e345b89dcd..6b6d57511a 100644 --- a/docs/topics/cache.txt +++ b/docs/topics/cache.txt @@ -639,6 +639,23 @@ equivalent: This feature is useful in avoiding repetition in templates. You can set the timeout in a variable, in one place, and just reuse that value. +.. function:: django.core.cache.utils.make_template_fragment_key(fragment_name, vary_on=None) + +If you want to obtain the cache key used for a cached fragment, you can use +``make_template_fragment_key``. ``fragment_name`` is the same as second argument +to the ``cache`` template tag; ``vary_on`` is a list of all additional arguments +passed to the tag. This function can be useful for invalidating or overwriting +a cached item, for example: + +.. code-block:: python + + >>> from django.core.cache import cache + >>> from django.core.cache.utils import make_template_fragment_key + # cache key for {% cache 500 sidebar username %} + >>> key = make_template_fragment_key('sidebar', [username]) + >>> cache.delete(key) # invalidates cached template fragment + + The low-level cache API ======================= |
