Django

Code

Changeset 6774

Show
Ignore:
Timestamp:
11/29/07 23:30:43 (1 year ago)
Author:
adrian
Message:

Edited docs and docstring changes from [6572] (new cache add() method)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/cache/backends/base.py

    r6572 r6774  
    1717    def add(self, key, value, timeout=None): 
    1818        """ 
    19         Set a value in the cache if the key does not already exist. If 
     19        Set a value in the cache if the key does not already exist. If 
    2020        timeout is given, that timeout will be used for the key; otherwise 
    2121        the default cache timeout will be used. 
     
    2525    def get(self, key, default=None): 
    2626        """ 
    27         Fetch a given key from the cache. If the key does not exist, return 
     27        Fetch a given key from the cache. If the key does not exist, return 
    2828        default, which itself defaults to None. 
    2929        """ 
     
    3232    def set(self, key, value, timeout=None): 
    3333        """ 
    34         Set a value in the cache. If timeout is given, that timeout will be 
     34        Set a value in the cache. If timeout is given, that timeout will be 
    3535        used for the key; otherwise the default cache timeout will be used. 
    3636        """ 
     
    4545    def get_many(self, keys): 
    4646        """ 
    47         Fetch a bunch of keys from the cache. For certain backends (memcached, 
     47        Fetch a bunch of keys from the cache. For certain backends (memcached, 
    4848        pgsql) this can be *much* faster when fetching multiple values. 
    4949 
    50         Returns a dict mapping each key in keys to its value. If the given 
     50        Returns a dict mapping each key in keys to its value. If the given 
    5151        key is missing, it will be missing from the response dict. 
    5252        """ 
     
    6565 
    6666    __contains__ = has_key 
    67  
  • django/trunk/docs/cache.txt

    r6736 r6774  
    371371    'has expired' 
    372372 
    373 To add a key only if it doesn't already exist, there is an add() method.  It 
    374 takes the same parameters as set(), but will not attempt to update the cache 
    375 if the key specified is already present:: 
     373**New in Django development version:** To add a key only if it doesn't already 
     374exist, use the ``add()`` method. It takes the same parameters as ``set()``, but 
     375it will not attempt to update the cache if the key specified is already present:: 
    376376 
    377377    >>> cache.set('add_key', 'Initial value') 
     
    380380    'Initial value' 
    381381 
    382 There's also a get_many() interface that only hits the cache once. get_many() 
     382There's also a ``get_many()`` interface that only hits the cache once. ``get_many()`` 
    383383returns a dictionary with all the keys you asked for that actually exist in the 
    384384cache (and haven't expired)::