diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-05-14 11:53:17 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-05-18 18:24:19 +0200 |
| commit | 958cdf65ae90d26236d1815bbba804729595ec7a (patch) | |
| tree | 4fdae4b8c04f4e3852cc418dd54f9ae49bb423cd /django/core/cache/__init__.py | |
| parent | a24fed399ced6be2e9dce4cf28db00c3ee21a21c (diff) | |
Fixed #32747 -- Prevented initialization of unused caches.
Thanks Alexander Ebral for the report.
Regression in 98e05ccde440cc9b768952cc10bc8285f4924e1f.
Diffstat (limited to 'django/core/cache/__init__.py')
| -rw-r--r-- | django/core/cache/__init__.py | 9 |
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() |
