mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +00:00
Fixed #22495 -- Locmem cache.add() failed with infinite timeouts
cache.add() incorrectly succeeded when there was an existing key with an infinite (None) timeout.
This commit is contained in:
parent
2ffa6ca73a
commit
af5f688392
4
django/core/cache/backends/locmem.py
vendored
4
django/core/cache/backends/locmem.py
vendored
@ -29,8 +29,8 @@ class LocMemCache(BaseCache):
|
|||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
|
||||||
with self._lock.writer():
|
with self._lock.writer():
|
||||||
exp = self._expire_info.get(key)
|
exp = self._expire_info.get(key, 0)
|
||||||
if exp is None or exp <= time.time():
|
if exp is not None and exp <= time.time():
|
||||||
self._set(key, pickled, timeout)
|
self._set(key, pickled, timeout)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
3
tests/cache/tests.py
vendored
3
tests/cache/tests.py
vendored
@ -490,6 +490,9 @@ class BaseCacheTests(object):
|
|||||||
|
|
||||||
cache.add('key2', 'ham', None)
|
cache.add('key2', 'ham', None)
|
||||||
self.assertEqual(cache.get('key2'), 'ham')
|
self.assertEqual(cache.get('key2'), 'ham')
|
||||||
|
added = cache.add('key1', 'new eggs', None)
|
||||||
|
self.assertEqual(added, False)
|
||||||
|
self.assertEqual(cache.get('key1'), 'eggs')
|
||||||
|
|
||||||
cache.set_many({'key3': 'sausage', 'key4': 'lobster bisque'}, None)
|
cache.set_many({'key3': 'sausage', 'key4': 'lobster bisque'}, None)
|
||||||
self.assertEqual(cache.get('key3'), 'sausage')
|
self.assertEqual(cache.get('key3'), 'sausage')
|
||||||
|
Loading…
Reference in New Issue
Block a user