3030]
3131
3232
33- def _monkey_patch_method (cache , name ):
33+ def _monkey_patch_method (cache , name , alias ):
3434 original_method = getattr (cache , name )
3535
3636 @functools .wraps (original_method )
@@ -39,15 +39,15 @@ def wrapper(*args, **kwargs):
3939 if panel is None :
4040 return original_method (* args , ** kwargs )
4141 else :
42- return panel ._record_call (cache , name , original_method , args , kwargs )
42+ return panel ._record_call (cache , alias , name , original_method , args , kwargs )
4343
4444 setattr (cache , name , wrapper )
4545
4646
47- def _monkey_patch_cache (cache ):
47+ def _monkey_patch_cache (cache , alias ):
4848 if not hasattr (cache , "_djdt_patched" ):
4949 for name in WRAPPED_CACHE_METHODS :
50- _monkey_patch_method (cache , name )
50+ _monkey_patch_method (cache , name , alias )
5151 cache ._djdt_patched = True
5252
5353
@@ -95,7 +95,7 @@ def wrapper(self, alias):
9595 cache = original_method (self , alias )
9696 panel = cls .current_instance ()
9797 if panel is not None :
98- _monkey_patch_cache (cache )
98+ _monkey_patch_cache (cache , alias )
9999 cache ._djdt_panel = panel
100100 return cache
101101
@@ -138,7 +138,7 @@ def _store_call_info(
138138 }
139139 )
140140
141- def _record_call (self , cache , name , original_method , args , kwargs ):
141+ def _record_call (self , cache , alias , name , original_method , args , kwargs ):
142142 # Some cache backends implement certain cache methods in terms of other cache
143143 # methods (e.g. get_or_set() in terms of get() and add()). In order to only
144144 # record the calls made directly by the user code, set the cache's _djdt_panel
@@ -161,7 +161,7 @@ def _record_call(self, cache, name, original_method, args, kwargs):
161161 kwargs = kwargs ,
162162 trace = get_stack_trace (skip = 2 ),
163163 template_info = get_template_info (),
164- backend = cache ,
164+ backend = alias ,
165165 )
166166 return value
167167
@@ -194,9 +194,10 @@ def enable_instrumentation(self):
194194 # requests. The monkey patch of CacheHander.create_connection() installed in
195195 # the .ready() method will ensure that any new cache connections that get opened
196196 # during this request will also be monkey patched.
197- for cache in caches .all (initialized_only = True ):
198- _monkey_patch_cache (cache )
199- cache ._djdt_panel = self
197+ for alias in caches :
198+ if hasattr (caches ._connections , alias ):
199+ _monkey_patch_cache (caches [alias ], alias )
200+ caches [alias ]._djdt_panel = self
200201 # Mark this panel instance as the current one for the active thread/async task
201202 # context. This will be used by the CacheHander.create_connection() monkey
202203 # patch.
0 commit comments