﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32747	CacheHandler initialize unused caches.	Alexander Ebral	Mariusz Felisiak	"After the commit: https://github.com/django/django/commit/98e05ccde440cc9b768952cc10bc8285f4924e1f 
logic of the method ""all"" from CacheHandler class was changed. 

Before: 

{{{
    def all(self):
        return getattr(self._caches, 'caches', {}).values()
}}}


This method returned connections that were created in !__getitem!__



Now:

{{{
    def all(self):
        return [self[alias] for alias in self]
}}}


Connections return for all ""CACHES"" from settings.py  (in case of absence - they are forcibly created in self[alias])

Which version of this method seems to be right? 

In my case this unnecessary mass initialization of custom diskcache-classes leads to io-lags.

Snippet that helped me:


{{{
import django.core.cache


def cache_getitem(self, alias, exists_only=False):
    try:
        return getattr(self._connections, alias)
    except AttributeError:
        if alias not in self.settings:
            raise self.exception_class(f""The connection '{alias}' doesn't exist."")
        if exists_only:
            return
    conn = self.create_connection(alias)
    setattr(self._connections, alias, conn)
    return conn


def cache_all(self):
    connections = [self.__getitem__(alias, exists_only=True) for alias in self]
    return [conn for conn in connections if conn is not None]


django.core.cache.CacheHandler.all = cache_all
django.core.cache.CacheHandler.__getitem__ = cache_getitem
}}}

"	Bug	closed	Core (Cache system)	3.2	Release blocker	fixed		Florian Apolloner	Accepted	1	0	0	0	0	0
