mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Fixed #26332 -- Fixed a race condition in BaseCache.get_or_set().
This commit is contained in:
committed by
Tim Graham
parent
b4250ea04a
commit
96ec67a7cf
10
django/core/cache/backends/base.py
vendored
10
django/core/cache/backends/base.py
vendored
@@ -154,8 +154,7 @@ class BaseCache(object):
|
||||
also be any callable. If timeout is given, that timeout will be used
|
||||
for the key; otherwise the default cache timeout will be used.
|
||||
|
||||
Returns the value of the key stored or retrieved on success,
|
||||
False on error.
|
||||
Return the value of the key stored or retrieved.
|
||||
"""
|
||||
if default is None:
|
||||
raise ValueError('You need to specify a value.')
|
||||
@@ -163,9 +162,10 @@ class BaseCache(object):
|
||||
if val is None:
|
||||
if callable(default):
|
||||
default = default()
|
||||
val = self.add(key, default, timeout=timeout, version=version)
|
||||
if val:
|
||||
return self.get(key, default, version)
|
||||
self.add(key, default, timeout=timeout, version=version)
|
||||
# Fetch the value again to avoid a race condition if another caller
|
||||
# added a value between the first get() and the add() above.
|
||||
return self.get(key, default, version=version)
|
||||
return val
|
||||
|
||||
def has_key(self, key, version=None):
|
||||
|
||||
Reference in New Issue
Block a user