summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorPrzemysław Suliga <suligap@gmail.com>2016-03-06 11:34:23 +0100
committerTim Graham <timograham@gmail.com>2016-03-08 11:45:09 -0500
commit76926f343a91e47bf5dc801373e9da2747d08e29 (patch)
treea40d98b39870d75effbd33490040fc166a709ee0 /django/core
parent809eb5ddeeca388b2a1d339f7d5ee1f29119ecea (diff)
[1.9.x] Fixed #26332 -- Fixed a race condition in BaseCache.get_or_set().
Backport of 96ec67a7cf89a136e793305343c5bba8521cdb47 from master
Diffstat (limited to 'django/core')
-rw-r--r--django/core/cache/backends/base.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index 75a131ac3a..12351c5bcd 100644
--- a/django/core/cache/backends/base.py
+++ b/django/core/cache/backends/base.py
@@ -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):