mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #27480 -- Added cache.touch().
This commit is contained in:
parent
8e960c5aba
commit
3246ad1065
9 changed files with 121 additions and 4 deletions
|
@ -734,6 +734,7 @@ a cached item, for example:
|
|||
>>> key = make_template_fragment_key('sidebar', [username])
|
||||
>>> cache.delete(key) # invalidates cached template fragment
|
||||
|
||||
.. _low-level-cache-api:
|
||||
|
||||
The low-level cache API
|
||||
=======================
|
||||
|
@ -891,6 +892,22 @@ from the cache, not just the keys set by your application. ::
|
|||
|
||||
>>> cache.clear()
|
||||
|
||||
``cache.touch()`` sets a new expiration for a key. For example, to update a key
|
||||
to expire 10 seconds from now::
|
||||
|
||||
>>> cache.touch('a', 10)
|
||||
True
|
||||
|
||||
Like other methods, the ``timeout`` argument is optional and defaults to the
|
||||
``TIMEOUT`` option of the appropriate backend in the :setting:`CACHES` setting.
|
||||
|
||||
``touch()`` returns ``True`` if the key was successfully touched, ``False``
|
||||
otherwise.
|
||||
|
||||
.. versionchanged:: 2.1
|
||||
|
||||
The ``cache.touch()`` method was added.
|
||||
|
||||
You can also increment or decrement a key that already exists using the
|
||||
``incr()`` or ``decr()`` methods, respectively. By default, the existing cache
|
||||
value will be incremented or decremented by 1. Other increment/decrement values
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue