mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #25840 -- Fixed BaseCache.get_or_set() on the DummyCache backend.
This also fixes a possible data eviction race condition between setting and getting a key. Another thread could remove the key before get_and_set() accesses it again. In this case, now the default value will be returned instead of None.
This commit is contained in:
9
tests/cache/tests.py
vendored
9
tests/cache/tests.py
vendored
@@ -202,6 +202,15 @@ class DummyCacheTests(SimpleTestCase):
|
||||
self.assertRaises(ValueError, cache.decr_version, 'answer')
|
||||
self.assertRaises(ValueError, cache.decr_version, 'does_not_exist')
|
||||
|
||||
def test_get_or_set(self):
|
||||
self.assertEqual(cache.get_or_set('mykey', 'default'), 'default')
|
||||
|
||||
def test_get_or_set_callable(self):
|
||||
def my_callable():
|
||||
return 'default'
|
||||
|
||||
self.assertEqual(cache.get_or_set('mykey', my_callable), 'default')
|
||||
|
||||
|
||||
def custom_key_func(key, key_prefix, version):
|
||||
"A customized cache key function"
|
||||
|
||||
Reference in New Issue
Block a user