#32747: CacheHandler logic issue
-----------------------------------------------+------------------------
               Reporter:  Alexander Ebral      |          Owner:  nobody
                   Type:  Bug                  |         Status:  new
              Component:  Core (Cache system)  |        Version:  3.2
               Severity:  Normal               |       Keywords:
           Triage Stage:  Unreviewed           |      Has patch:  0
    Needs documentation:  0                    |    Needs tests:  0
Patch needs improvement:  0                    |  Easy pickings:  0
                  UI/UX:  0                    |
-----------------------------------------------+------------------------
 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
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32747>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.f00286d2bf6919229005ed8de4fb65ab%40djangoproject.com.

Reply via email to