Jason Moiron avatar Jason Moiron committed a6b9586

fixes for django-1.3 which include a fix to the Pylibmc based backend because of the way it interprets zero (as an instantaneous timeout: http://sendapatch.se/projects/pylibmc/misc.html) and fixes the settings file to have a proper memcached sample CACHES setting

Comments (0)

Files changed (4)

johnny/backends/memcached.py

     cache class allows for non-expiring cache writes on certain backends,
     notably memcached."""
     def _get_memcache_timeout(self, timeout=None):
-        if timeout == 0: return 0
+        if timeout == 0: return 0 #2591999
         return super(CacheClass, self)._get_memcache_timeout(timeout)
 
 if django.VERSION[:2] > (1, 2):
     class MemcachedCache(memcached.MemcachedCache):
         def _get_memcache_timeout(self, timeout=None):
-            if timeout == 0: return 0
+            if timeout == 0: return 0 #2591999
             return super(MemcachedCache, self)._get_memcache_timeout(timeout)
 
     class PyLibMCCache(memcached.PyLibMCCache):
         def _get_memcache_timeout(self, timeout=None):
-            if timeout == 0: return 0
+            # pylibmc doesn't like our definition of 0
+            if timeout == 0: return 2591999
             return super(PyLibMCCache, self)._get_memcache_timeout(timeout)
         """Creates a random generation value for a single table name"""
         key = self.keygen.gen_table_key(table, db)
         val = self.cache_backend.get(key, None, db)
+        #print str(val).ljust(32), key
         if val == None:
             val = self.keygen.random_generator()
             self.cache_backend.set(key, val, 0, db)

johnny/transaction.py

 
 
 class TransactionManager(object):
-    """
-    TransactionManager is a wrapper around a cache_backend that is transaction aware in django.
-    Basically, if we are in a transaction it will return the locally cached version.
-    On rollback, it will flush all local caches
-    On commit, it will push them up to the cache backend
+    """TransactionManager is a wrapper around a cache_backend that is
+    transaction aware.
+
+    If we are in a transaction, it will return the locally cached version.
+
+      * On rollback, it will flush all local caches
+      * On commit, it will push them up to the real shared cache backend 
+        (ex. memcached).
     """
     _patched_var = False
     def __init__(self, cache_backend, keygen):
             using = using[0:68] + self.keygen.gen_key(using[68:])
         return using
 
-    def set(self, key, val, timeout = 0, using=None):
+    def set(self, key, val, timeout=None, using=None):
         """
         Set will be using the generational key, so if another thread
         bumps this key, the localstore version will still be invalid.
         If the key is bumped during a transaction it will be new
         to the global cache on commit, so it will still be a bump.
         """
-        if not timeout:
+        if timeout is None:
             timeout = self.timeout
         if self.is_managed() and self._patched_var:
             self.local[key] = val
             #1.1 version
             original()
             self._flush(commit=commit)
+
         if django.VERSION[:2] == (1,1):
             return newfun11
         elif django.VERSION[:2] in ((1,2), (1,3)):
             return newfun
         return original
+
     def _uses_savepoints(self):
         return connection.features.uses_savepoints
 
 ADMIN_MEDIA_PREFIX = '/media/'
 
 if django.VERSION[:2] < (1, 3):
-    CACHE_BACKEND="johnny.backends.locmem://"
-    #CACHE_BACKEND="johnny.backends.memcached://localhost:11211/"
+    #CACHE_BACKEND="johnny.backends.locmem://"
+    CACHE_BACKEND="johnny.backends.memcached://localhost:11211/"
     #CACHE_BACKEND="johnny.backends.filebased:///tmp/johnny_cache.cc"
 else:
-    CACHE = { 'default' : { 'BACKEND': 'johnny.backends.locmem.LocMemCache' }}
+    #CACHES = { 'default' : { 'BACKEND': 'johnny.backends.locmem.LocMemCache' }}
+    CACHES = {
+        'default' : {
+            'BACKEND': 'johnny.backends.memcached.MemcachedCache',
+            'LOCATION': ['localhost:11211'],
+        }
+    }
 
 
 # Make this unique, and don't share it with anybody.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.