mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #28601 -- Prevented cache.get_or_set() from caching None if default is a callable that returns None.
This commit is contained in:
12
django/core/cache/backends/base.py
vendored
12
django/core/cache/backends/base.py
vendored
@@ -155,13 +155,15 @@ class BaseCache:
|
||||
Return the value of the key stored or retrieved.
|
||||
"""
|
||||
val = self.get(key, version=version)
|
||||
if val is None and default is not None:
|
||||
if val is None:
|
||||
if callable(default):
|
||||
default = default()
|
||||
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)
|
||||
if default is not None:
|
||||
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