summaryrefslogtreecommitdiff
path: root/django/core/cache
diff options
context:
space:
mode:
Diffstat (limited to 'django/core/cache')
-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()