diff options
| author | Aymeric Augustin | 2013-11-10 09:58:56 -0800 |
|---|---|---|
| committer | Aymeric Augustin | 2013-11-10 09:58:56 -0800 |
| commit | d889bf25d98e6d3c8dde01b207f9ba5f3d91a806 (patch) | |
| tree | 97967ae5b01c7531954b983606bc78498a128d8a /debug_toolbar/panels/cache.py | |
| parent | 8c7a8ec6529063853c9ff36da72a38841ca5e235 (diff) | |
| parent | f5eaa8ebb0d1ca13aa2453ef88bb1eb223757716 (diff) | |
| download | django-debug-toolbar-d889bf25d98e6d3c8dde01b207f9ba5f3d91a806.tar.bz2 | |
Merge pull request #453 from aaugustin/disable-instrumentation-for-disabled-panels
Disable instrumentation for disabled panels
Diffstat (limited to 'debug_toolbar/panels/cache.py')
| -rw-r--r-- | debug_toolbar/panels/cache.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/debug_toolbar/panels/cache.py b/debug_toolbar/panels/cache.py index 57da54b..a6b06ce 100644 --- a/debug_toolbar/panels/cache.py +++ b/debug_toolbar/panels/cache.py @@ -6,7 +6,7 @@ import time from django.conf import settings from django.core import cache -from django.core.cache import get_cache as base_get_cache +from django.core.cache import cache as original_cache, get_cache as original_get_cache from django.core.cache.backends.base import BaseCache from django.dispatch import Signal from django.template import Node @@ -123,6 +123,10 @@ class CacheStatTracker(BaseCache): return self.cache.decr_version(*args, **kwargs) +def get_cache(*args, **kwargs): + return CacheStatTracker(original_get_cache(*args, **kwargs)) + + class CacheDebugPanel(DebugPanel): """ Panel that displays the cache statistics. @@ -195,6 +199,16 @@ class CacheDebugPanel(DebugPanel): 'Cache calls from %(count)d backends', count) % dict(count=count) + def enable_instrumentation(self): + # This isn't thread-safe because cache connections aren't thread-local + # in Django, unlike database connections. + cache.cache = CacheStatTracker(cache.cache) + cache.get_cache = get_cache + + def disable_instrumentation(self): + cache.cache = original_cache + cache.get_cache = original_get_cache + def process_response(self, request, response): self.record_stats({ 'total_calls': len(self.calls), @@ -204,12 +218,3 @@ class CacheDebugPanel(DebugPanel): 'misses': self.misses, 'counts': self.counts, }) - - -def get_cache_debug(*args, **kwargs): - base_cache = base_get_cache(*args, **kwargs) - return CacheStatTracker(base_cache) - - -cache.cache = CacheStatTracker(cache.cache) -cache.get_cache = get_cache_debug |
