summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-14 11:53:17 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-18 20:23:26 +0200
commit41e2aa7eb24e564f6984e6e6660b8e5ff5edbd9d (patch)
tree4ee05d6cc70e5a831278961cccd428139336ba04 /django
parent349bb58b8a0b6f4b98193dbfe369e41b8780f225 (diff)
[3.2.x] Fixed #32747 -- Prevented initialization of unused caches.
Thanks Alexander Ebral for the report. Regression in 98e05ccde440cc9b768952cc10bc8285f4924e1f. Backport of 958cdf65ae90d26236d1815bbba804729595ec7a from main
Diffstat (limited to 'django')
-rw-r--r--django/core/cache/__init__.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py
index 05ef3897d0..a311b50af6 100644
--- a/django/core/cache/__init__.py
+++ b/django/core/cache/__init__.py
@@ -43,6 +43,13 @@ class CacheHandler(BaseConnectionHandler):
) from e
return backend_cls(location, params)
+ def all(self, initialized_only=False):
+ return [
+ self[alias] for alias in self
+ # If initialized_only is True, return only initialized caches.
+ if not initialized_only or hasattr(self._connections, alias)
+ ]
+
caches = CacheHandler()
@@ -52,7 +59,7 @@ cache = ConnectionProxy(caches, DEFAULT_CACHE_ALIAS)
def close_caches(**kwargs):
# Some caches need to do a cleanup at the end of a request cycle. If not
# implemented in a particular backend cache.close() is a no-op.
- for cache in caches.all():
+ for cache in caches.all(initialized_only=True):
cache.close()