Fixed #32076 -- Added async methods to BaseCache.

This also makes DummyCache async-compatible.
This commit is contained in:
Andrew-Chen-Wang 2020-10-16 10:16:55 -04:00 committed by Mariusz Felisiak
parent 42dfa97e19
commit 301a85a12f
4 changed files with 312 additions and 1 deletions

View file

@ -187,7 +187,13 @@ Minor features
Cache
~~~~~
* ...
* The new async API for ``django.core.cache.backends.base.BaseCache`` begins
the process of making cache backends async-compatible. The new async methods
all have ``a`` prefixed names, e.g. ``aadd()``, ``aget()``, ``aset()``,
``aget_or_set()``, or ``adelete_many()``.
Going forward, the ``a`` prefix will be used for async variants of methods
generally.
CSRF
~~~~

View file

@ -808,6 +808,8 @@ Accessing the cache
This object is equivalent to ``caches['default']``.
.. _cache-basic-interface:
Basic usage
-----------
@ -997,6 +999,16 @@ the cache backend.
For caches that don't implement ``close`` methods it is a no-op.
.. note::
The async variants of base methods are prefixed with ``a``, e.g.
``cache.aadd()`` or ``cache.adelete_many()``. See `Asynchronous support`_
for more details.
.. versionchanged:: 4.0
The async variants of methods were added to the ``BaseCache``.
.. _cache_key_prefixing:
Cache key prefixing
@ -1123,6 +1135,25 @@ instance, to do this for the ``locmem`` backend, put this code in a module::
...and use the dotted Python path to this class in the
:setting:`BACKEND <CACHES-BACKEND>` portion of your :setting:`CACHES` setting.
.. _asynchronous_support:
Asynchronous support
====================
.. versionadded:: 4.0
Django has developing support for asynchronous cache backends, but does not
yet support asynchronous caching. It will be coming in a future release.
``django.core.cache.backends.base.BaseCache`` has async variants of :ref:`all
base methods <cache-basic-interface>`. By convention, the asynchronous versions
of all methods are prefixed with ``a``. By default, the arguments for both
variants are the same::
>>> await cache.aset('num', 1)
>>> await cache.ahas_key('num')
True
.. _downstream-caches:
Downstream caches