Changes between Initial Version and Version 1 of Ticket #2341


Ignore:
Timestamp:
07/13/2006 09:38:06 PM (9 years ago)
Author:
adrian
Comment:

Eh, I'm not sure this has general interest, so I'm marking it as a wontfix. Memcached already has its own framework for viewing this sort of data, BTW, and although the other backends don't, I don't see this as a big deal.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #2341

    • Property Status changed from new to closed
    • Property Resolution changed from to wontfix
  • Ticket #2341 – Description

    initial v1  
    77+++ __init__.py (working copy)
    88@@ -18,6 +18,8 @@
    9  from cgi import parse_qsl
    10  from django.conf import settings
    11  from django.core.cache.backends.base import InvalidCacheBackendError
     9 from cgi import parse_qsl
     10 from django.conf import settings
     11 from django.core.cache.backends.base import InvalidCacheBackendError
    1212+from django.core import signals
    1313+from django.dispatch import dispatcher
    14  
    15  BACKENDS = {
    16      # name for use in settings file --> name of module in "backends" directory
     14 
     15 BACKENDS = {
     16    # name for use in settings file --> name of module in "backends" directory
    1717@@ -48,7 +50,55 @@
    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  
     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 
    2929+class CacheDebugWrapper(object):
    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 = []
     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 = []
    3838+
    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
     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
    4848+
    49 +    def set(self, key, value, timeout=0):
    50 +        self.sets += 1
    51 +        self._cache.set(key, value, timeout)
     49+    def set(self, key, value, timeout=0):
     50+        self.sets += 1
     51+        self._cache.set(key, value, timeout)
    5252+
    53 +    def delete(self, key):
    54 +        self.deletes += 1
    55 +        self._cache.delete(key)
     53+    def delete(self, key):
     54+        self.deletes += 1
     55+        self._cache.delete(key)
    5656+
    57 +    def get_many(self, keys):
    58 +        self.get_manys += 1
    59 +        return self._cache.get_multi(keys)
     57+    def get_many(self, keys):
     58+        self.get_manys += 1
     59+        return self._cache.get_multi(keys)
    6060+
    6161+def reset_queries():
    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 = []
     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 = []
    7070+
    7171+
    7272+dispatcher.connect(reset_queries, signal=signals.request_started)
    7373+
    74  cache = get_cache(settings.CACHE_BACKEND)
     74 cache = get_cache(settings.CACHE_BACKEND)
    7575}}}
Back to Top