Changeset 8278
- Timestamp:
- 08/09/08 22:52:21 (3 months ago)
- Files:
-
- django/trunk/django/core/cache/backends/base.py (modified) (1 diff)
- django/trunk/django/core/cache/backends/db.py (modified) (2 diffs)
- django/trunk/django/core/cache/backends/dummy.py (modified) (1 diff)
- django/trunk/django/core/cache/backends/filebased.py (modified) (1 diff)
- django/trunk/django/core/cache/backends/locmem.py (modified) (1 diff)
- django/trunk/django/core/cache/backends/memcached.py (modified) (1 diff)
- django/trunk/docs/cache.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/cache/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/cache/backends/base.py
r8084 r8278 20 20 timeout is given, that timeout will be used for the key; otherwise 21 21 the default cache timeout will be used. 22 23 Returns True if the value was stored, False otherwise. 22 24 """ 23 25 raise NotImplementedError django/trunk/django/core/cache/backends/db.py
r6589 r8278 39 39 40 40 def set(self, key, value, timeout=None): 41 returnself._base_set('set', key, value, timeout)41 self._base_set('set', key, value, timeout) 42 42 43 43 def add(self, key, value, timeout=None): … … 63 63 except DatabaseError: 64 64 # To be threadsafe, updates/inserts are allowed to fail silently 65 pass65 return False 66 66 else: 67 67 transaction.commit_unless_managed() 68 return True 68 69 69 70 def delete(self, key): django/trunk/django/core/cache/backends/dummy.py
r6572 r8278 8 8 9 9 def add(self, *args, **kwargs): 10 pass10 return True 11 11 12 12 def get(self, key, default=None): django/trunk/django/core/cache/backends/filebased.py
r8193 r8278 33 33 def add(self, key, value, timeout=None): 34 34 if self.has_key(key): 35 return None35 return False 36 36 37 37 self.set(key, value, timeout) 38 return True 38 39 39 40 def get(self, key, default=None): django/trunk/django/core/cache/backends/locmem.py
r8090 r8278 37 37 try: 38 38 self._set(key, pickle.dumps(value), timeout) 39 return True 39 40 except pickle.PickleError: 40 41 pass 42 return False 41 43 finally: 42 44 self._lock.writer_leaves() django/trunk/django/core/cache/backends/memcached.py
r6572 r8278 18 18 19 19 def add(self, key, value, timeout=0): 20 self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout)20 return self._cache.add(key.encode('ascii', 'ignore'), value, timeout or self.default_timeout) 21 21 22 22 def get(self, key, default=None): django/trunk/docs/cache.txt
r8261 r8278 411 411 'Initial value' 412 412 413 There's also a ``get_many()`` interface that only hits the cache once. ``get_many()`` 414 returns a dictionary with all the keys you asked for that actually exist in the 415 cache (and haven't expired):: 413 If you need to know whether ``add()`` stored a value in the cache, you can 414 check the return value. It will return ``True`` if the value was stored, 415 ``False`` otherwise. 416 417 There's also a ``get_many()`` interface that only hits the cache once. 418 ``get_many()`` returns a dictionary with all the keys you asked for that 419 actually exist in the cache (and haven't expired):: 416 420 417 421 >>> cache.set('a', 1) django/trunk/tests/regressiontests/cache/tests.py
r8193 r8278 32 32 # test add (only add if key isn't already in cache) 33 33 cache.add("addkey1", "value") 34 cache.add("addkey1", "newvalue") 34 result = cache.add("addkey1", "newvalue") 35 self.assertEqual(result, False) 35 36 self.assertEqual(cache.get("addkey1"), "value") 36 37
