Ticket #17287: patch.diff
File patch.diff, 1.9 KB (added by , 13 years ago) |
---|
-
django/core/cache/backends/locmem.py
87 87 finally: 88 88 self._lock.writer_leaves() 89 89 90 def incr(self, key, delta=1, version=None): 91 value = self.get(key, version=version) 92 if value is None: 93 raise ValueError("Key '%s' not found" % key) 94 new_value = value + delta 95 key = self.make_key(key, version=version) 96 self._lock.writer_enters() 97 try: 98 pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL) 99 self._cache[key] = pickled 100 except pickle.PickleError: 101 pass 102 finally: 103 self._lock.writer_leaves() 104 return new_value 105 90 106 def has_key(self, key, version=None): 91 107 key = self.make_key(key, version=version) 92 108 self.validate_key(key) -
tests/regressiontests/cache/tests.py
865 865 self.assertEqual(mirror_cache.get('value1'), 42) 866 866 self.assertEqual(other_cache.get('value1'), None) 867 867 868 def test_incr_decr_timeout(self): 869 key = 'value' 870 _key = self.cache.make_key(key) 871 self.cache.set(key, 1, timeout=self.cache.default_timeout*10) 872 expire = self.cache._expire_info[_key] 873 self.cache.incr(key) 874 self.assertEqual(expire, self.cache._expire_info[_key]) 875 self.cache.decr(key) 876 self.assertEqual(expire, self.cache._expire_info[_key]) 868 877 869 878 # memcached backend isn't guaranteed to be available. 870 879 # To check the memcached backend, the test settings file will