Changes between Initial Version and Version 1 of Ticket #2341
- Timestamp:
- Jul 13, 2006, 9:38:06 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #2341
- Property Resolution → wontfix
- Property Status new → closed
-
Ticket #2341 – Description
initial v1 7 7 +++ __init__.py (working copy) 8 8 @@ -18,6 +18,8 @@ 9 10 11 9 from cgi import parse_qsl 10 from django.conf import settings 11 from django.core.cache.backends.base import InvalidCacheBackendError 12 12 +from django.core import signals 13 13 +from django.dispatch import dispatcher 14 15 16 14 15 BACKENDS = { 16 # name for use in settings file --> name of module in "backends" directory 17 17 @@ -48,7 +50,55 @@ 18 19 20 21 - 22 - 23 + 24 + 25 + 26 + 27 + 28 18 if host.endswith('/'): 19 host = host[:-1] 20 21 - cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], '', '', ['']), 'CacheClass') 22 - return cache_class(host, params) 23 + cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], '', '', ['']), 'CacheClass') 24 + if settings.DEBUG: 25 + return CacheDebugWrapper( cache_class(host,params )) 26 + else: 27 + return cache_class(host, params) 28 29 29 +class CacheDebugWrapper(object): 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 30 + def __init__(self, real_cache ): 31 + self._cache = real_cache 32 + self.gets = 0 33 + self.get_hits = 0 34 + self.sets = 0 35 + self.deletes= 0 36 + self.get_manys= 0 37 + self.queries = [] 38 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 39 + def get(self,key,default=None): 40 + self.gets += 1 41 + val = self._cache.get( key ) 42 + self.queries.append( key ) 43 + if val is None: 44 + return default 45 + else: 46 + self.get_hits += 1 47 + return val 48 48 + 49 + 50 + 51 + 49 + def set(self, key, value, timeout=0): 50 + self.sets += 1 51 + self._cache.set(key, value, timeout) 52 52 + 53 + 54 + 55 + 53 + def delete(self, key): 54 + self.deletes += 1 55 + self._cache.delete(key) 56 56 + 57 + 58 + 59 + 57 + def get_many(self, keys): 58 + self.get_manys += 1 59 + return self._cache.get_multi(keys) 60 60 + 61 61 +def reset_queries(): 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 62 + if settings.DEBUG: 63 + cache.queries = [] 64 + cache.gets = 0 65 + cache.get_hits = 0 66 + cache.sets = 0 67 + cache.deletes= 0 68 + cache.get_manys= 0 69 + cache.queries = [] 70 70 + 71 71 + 72 72 +dispatcher.connect(reset_queries, signal=signals.request_started) 73 73 + 74 74 cache = get_cache(settings.CACHE_BACKEND) 75 75 }}}