Fixed #27480 -- Added cache.touch().

This commit is contained in:
Nicolas Noé 2018-04-27 23:48:35 +02:00 committed by Tim Graham
parent 8e960c5aba
commit 3246ad1065
9 changed files with 121 additions and 4 deletions

View file

@ -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