30
30
]
31
31
32
32
33
- def _monkey_patch_method (cache , name ):
33
+ def _monkey_patch_method (cache , name , alias ):
34
34
original_method = getattr (cache , name )
35
35
36
36
@functools .wraps (original_method )
@@ -39,15 +39,15 @@ def wrapper(*args, **kwargs):
39
39
if panel is None :
40
40
return original_method (* args , ** kwargs )
41
41
else :
42
- return panel ._record_call (cache , name , original_method , args , kwargs )
42
+ return panel ._record_call (cache , alias , name , original_method , args , kwargs )
43
43
44
44
setattr (cache , name , wrapper )
45
45
46
46
47
- def _monkey_patch_cache (cache ):
47
+ def _monkey_patch_cache (cache , alias ):
48
48
if not hasattr (cache , "_djdt_patched" ):
49
49
for name in WRAPPED_CACHE_METHODS :
50
- _monkey_patch_method (cache , name )
50
+ _monkey_patch_method (cache , name , alias )
51
51
cache ._djdt_patched = True
52
52
53
53
@@ -95,7 +95,7 @@ def wrapper(self, alias):
95
95
cache = original_method (self , alias )
96
96
panel = cls .current_instance ()
97
97
if panel is not None :
98
- _monkey_patch_cache (cache )
98
+ _monkey_patch_cache (cache , alias )
99
99
cache ._djdt_panel = panel
100
100
return cache
101
101
@@ -138,7 +138,7 @@ def _store_call_info(
138
138
}
139
139
)
140
140
141
- def _record_call (self , cache , name , original_method , args , kwargs ):
141
+ def _record_call (self , cache , alias , name , original_method , args , kwargs ):
142
142
# Some cache backends implement certain cache methods in terms of other cache
143
143
# methods (e.g. get_or_set() in terms of get() and add()). In order to only
144
144
# 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):
161
161
kwargs = kwargs ,
162
162
trace = get_stack_trace (skip = 2 ),
163
163
template_info = get_template_info (),
164
- backend = cache ,
164
+ backend = alias ,
165
165
)
166
166
return value
167
167
@@ -194,9 +194,10 @@ def enable_instrumentation(self):
194
194
# requests. The monkey patch of CacheHander.create_connection() installed in
195
195
# the .ready() method will ensure that any new cache connections that get opened
196
196
# 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
200
201
# Mark this panel instance as the current one for the active thread/async task
201
202
# context. This will be used by the CacheHander.create_connection() monkey
202
203
# patch.
0 commit comments