mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #30181 -- Corrected note about storing None in the cache.
This commit is contained in:
parent
8f384505ee
commit
d23dad5778
@ -839,9 +839,21 @@ If the object doesn't exist in the cache, ``cache.get()`` returns ``None``::
|
|||||||
>>> cache.get('my_key')
|
>>> cache.get('my_key')
|
||||||
None
|
None
|
||||||
|
|
||||||
We advise against storing the literal value ``None`` in the cache, because you
|
If you need to determine whether the object exists in the cache and you have
|
||||||
won't be able to distinguish between your stored ``None`` value and a cache
|
stored a literal value ``None``, use a sentinel object as the default::
|
||||||
miss signified by a return value of ``None``.
|
|
||||||
|
>>> sentinel = object()
|
||||||
|
>>> cache.get('my_key', sentinel) is sentinel
|
||||||
|
False
|
||||||
|
>>> # Wait 30 seconds for 'my_key' to expire...
|
||||||
|
>>> cache.get('my_key', sentinel) is sentinel
|
||||||
|
True
|
||||||
|
|
||||||
|
.. admonition:: ``MemcachedCache``
|
||||||
|
|
||||||
|
Due to a ``python-memcached`` limitation, it's not possible to distinguish
|
||||||
|
between stored ``None`` value and a cache miss signified by a return value
|
||||||
|
of ``None`` on the deprecated ``MemcachedCache`` backend.
|
||||||
|
|
||||||
``cache.get()`` can take a ``default`` argument. This specifies which value to
|
``cache.get()`` can take a ``default`` argument. This specifies which value to
|
||||||
return if the object doesn't exist in the cache::
|
return if the object doesn't exist in the cache::
|
||||||
|
Loading…
Reference in New Issue
Block a user