mirror of https://github.com/django/django.git
Edited docs and docstring changes from [6572] (new cache add() method)
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6774 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7ea174ef14
commit
9e762f4407
|
@ -16,7 +16,7 @@ class BaseCache(object):
|
||||||
|
|
||||||
def add(self, key, value, timeout=None):
|
def add(self, key, value, timeout=None):
|
||||||
"""
|
"""
|
||||||
Set a value in the cache if the key does not already exist. If
|
Set a value in the cache if the key does not already exist. If
|
||||||
timeout is given, that timeout will be used for the key; otherwise
|
timeout is given, that timeout will be used for the key; otherwise
|
||||||
the default cache timeout will be used.
|
the default cache timeout will be used.
|
||||||
"""
|
"""
|
||||||
|
@ -24,14 +24,14 @@ class BaseCache(object):
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
"""
|
"""
|
||||||
Fetch a given key from the cache. If the key does not exist, return
|
Fetch a given key from the cache. If the key does not exist, return
|
||||||
default, which itself defaults to None.
|
default, which itself defaults to None.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set(self, key, value, timeout=None):
|
def set(self, key, value, timeout=None):
|
||||||
"""
|
"""
|
||||||
Set a value in the cache. If timeout is given, that timeout will be
|
Set a value in the cache. If timeout is given, that timeout will be
|
||||||
used for the key; otherwise the default cache timeout will be used.
|
used for the key; otherwise the default cache timeout will be used.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -44,10 +44,10 @@ class BaseCache(object):
|
||||||
|
|
||||||
def get_many(self, keys):
|
def get_many(self, keys):
|
||||||
"""
|
"""
|
||||||
Fetch a bunch of keys from the cache. For certain backends (memcached,
|
Fetch a bunch of keys from the cache. For certain backends (memcached,
|
||||||
pgsql) this can be *much* faster when fetching multiple values.
|
pgsql) this can be *much* faster when fetching multiple values.
|
||||||
|
|
||||||
Returns a dict mapping each key in keys to its value. If the given
|
Returns a dict mapping each key in keys to its value. If the given
|
||||||
key is missing, it will be missing from the response dict.
|
key is missing, it will be missing from the response dict.
|
||||||
"""
|
"""
|
||||||
d = {}
|
d = {}
|
||||||
|
@ -64,4 +64,3 @@ class BaseCache(object):
|
||||||
return self.get(key) is not None
|
return self.get(key) is not None
|
||||||
|
|
||||||
__contains__ = has_key
|
__contains__ = has_key
|
||||||
|
|
||||||
|
|
|
@ -370,16 +370,16 @@ get() can take a ``default`` argument::
|
||||||
>>> cache.get('my_key', 'has expired')
|
>>> cache.get('my_key', 'has expired')
|
||||||
'has expired'
|
'has expired'
|
||||||
|
|
||||||
To add a key only if it doesn't already exist, there is an add() method. It
|
**New in Django development version:** To add a key only if it doesn't already
|
||||||
takes the same parameters as set(), but will not attempt to update the cache
|
exist, use the ``add()`` method. It takes the same parameters as ``set()``, but
|
||||||
if the key specified is already present::
|
it will not attempt to update the cache if the key specified is already present::
|
||||||
|
|
||||||
>>> cache.set('add_key', 'Initial value')
|
>>> cache.set('add_key', 'Initial value')
|
||||||
>>> cache.add('add_key', 'New value')
|
>>> cache.add('add_key', 'New value')
|
||||||
>>> cache.get('add_key')
|
>>> cache.get('add_key')
|
||||||
'Initial value'
|
'Initial value'
|
||||||
|
|
||||||
There's also a get_many() interface that only hits the cache once. get_many()
|
There's also a ``get_many()`` interface that only hits the cache once. ``get_many()``
|
||||||
returns a dictionary with all the keys you asked for that actually exist in the
|
returns a dictionary with all the keys you asked for that actually exist in the
|
||||||
cache (and haven't expired)::
|
cache (and haven't expired)::
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue