Commits

Mikhail Korobov committed 9af5755

django 1.3 compatibility (that's not the same as django 1.3 support)

Comments (0)

Files changed (2)

cache_utils/group_backend.py

 import time
 from django.core.cache.backends.memcached import CacheClass as MemcachedCacheClass
 from django.conf import settings
+from django.utils.encoding import smart_str
+
 from cache_utils.utils import sanitize_memcached_key
 
 # This prefix is appended to the group name to prevent cache key clashes.
 _VERSION_PREFIX = getattr(settings, 'VERSION', "")
 _KEY_PREFIX = "_group::"
 
+
 # MINT_DELAY is an upper bound on how long any value should take to
 # be generated (in seconds)
 MINT_DELAY = 30
             key = "%s:%s-%s" % (group, key, hashkey)
         return sanitize_memcached_key(key)
 
+    def make_key(self, key, *args, **kwargs):
+        """
+        A hack to make backend work correctly with django 1.3.
+
+        Key prefixes and cache versions are now supported out of box but
+        this class uses its own settings and in order to provide
+        backward compatibility django's new features are not used.
+        """
+        return smart_str(key)
+
     def _get_hashkey(self, group):
         """ This can be useful sometimes if you're doing a very large number
             of operations and you want to avoid all of the extra cache hits.

test_project/settings.py

 PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
 sys.path.insert(0, os.path.dirname(PROJECT_ROOT))
 
+# django < 1.3
 CACHE_BACKEND = 'cache_utils.group_backend://localhost:11211/' #?timeout=60
 
+# django 1.3+
+CACHES = {
+    'default': {
+        'BACKEND': 'cache_utils.group_backend.CacheClass',
+        'LOCATION': '127.0.0.1:11211',
+    },
+}
+
 DATABASE_ENGINE = 'sqlite3'
 DATABASE_NAME = ':memory:'
 
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.