mirror of https://github.com/django/django.git
Add documentation for get_caches function
This commit is contained in:
parent
89136b2725
commit
2315f1a2ee
|
@ -673,12 +673,27 @@ dictionaries, lists of model objects, and so forth. (Most common Python objects
|
||||||
can be pickled; refer to the Python documentation for more information about
|
can be pickled; refer to the Python documentation for more information about
|
||||||
pickling.)
|
pickling.)
|
||||||
|
|
||||||
|
Accessing the cache
|
||||||
|
-------------------
|
||||||
|
|
||||||
The cache module, ``django.core.cache``, has a ``cache`` object that's
|
The cache module, ``django.core.cache``, has a ``cache`` object that's
|
||||||
automatically created from the ``'default'`` entry in the :setting:`CACHES`
|
automatically created from the ``'default'`` entry in the :setting:`CACHES`
|
||||||
setting::
|
setting::
|
||||||
|
|
||||||
>>> from django.core.cache import cache
|
>>> from django.core.cache import cache
|
||||||
|
|
||||||
|
If you have multiple caches defined in :setting:`CACHES`, then you can use
|
||||||
|
:func:`django.core.cache.get_cache` to retrieve a cache object for any key::
|
||||||
|
|
||||||
|
>>> from django.core.cache import get_cache
|
||||||
|
>>> cache = get_cache('alternate')
|
||||||
|
|
||||||
|
If the named key does not exist, :exc:`InvalidCacheBackendError` will be raised.
|
||||||
|
|
||||||
|
|
||||||
|
Basic usage
|
||||||
|
-----------
|
||||||
|
|
||||||
The basic interface is ``set(key, value, timeout)`` and ``get(key)``::
|
The basic interface is ``set(key, value, timeout)`` and ``get(key)``::
|
||||||
|
|
||||||
>>> cache.set('my_key', 'hello, world!', 30)
|
>>> cache.set('my_key', 'hello, world!', 30)
|
||||||
|
@ -686,7 +701,7 @@ The basic interface is ``set(key, value, timeout)`` and ``get(key)``::
|
||||||
'hello, world!'
|
'hello, world!'
|
||||||
|
|
||||||
The ``timeout`` argument is optional and defaults to the ``timeout``
|
The ``timeout`` argument is optional and defaults to the ``timeout``
|
||||||
argument of the ``'default'`` backend in :setting:`CACHES` setting
|
argument of the appropriate backend in the :setting:`CACHES` setting
|
||||||
(explained above). It's the number of seconds the value should be stored
|
(explained above). It's the number of seconds the value should be stored
|
||||||
in the cache.
|
in the cache.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue