From 958cdf65ae90d26236d1815bbba804729595ec7a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 14 May 2021 11:53:17 +0200 Subject: Fixed #32747 -- Prevented initialization of unused caches. Thanks Alexander Ebral for the report. Regression in 98e05ccde440cc9b768952cc10bc8285f4924e1f. --- django/core/cache/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'django/core/cache') 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() -- cgit v1.3