1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #17287 -- Prevented LocMemCache.incr/decr from changing key expiry time. Thanks Ivan Virabyan for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17151 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Carl Meyer
2011-11-26 22:27:16 +00:00
parent 9c41437798
commit 1086a9a845
2 changed files with 26 additions and 0 deletions

View File

@@ -87,6 +87,22 @@ class LocMemCache(BaseCache):
finally:
self._lock.writer_leaves()
def incr(self, key, delta=1, version=None):
value = self.get(key, version=version)
if value is None:
raise ValueError("Key '%s' not found" % key)
new_value = value + delta
key = self.make_key(key, version=version)
self._lock.writer_enters()
try:
pickled = pickle.dumps(new_value, pickle.HIGHEST_PROTOCOL)
self._cache[key] = pickled
except pickle.PickleError:
pass
finally:
self._lock.writer_leaves()
return new_value
def has_key(self, key, version=None):
key = self.make_key(key, version=version)
self.validate_key(key)