Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJeff Balogh <me@jeffbalogh.org>2010-02-02 04:49:20 (GMT)
committer Jeff Balogh <me@jeffbalogh.org>2010-02-04 22:30:07 (GMT)
commit5a14d8820350a7f9411d5929add11ad7302df146 (patch)
tree96ba49d0f3113d3935f14111fb29c3ea16a72176 /lib
parent990a82cbd4142a39bdacd1d5013e284082bc237b (diff)
move key generation into a function
Diffstat (limited to 'lib')
-rw-r--r--lib/caching/base.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/caching/base.py b/lib/caching/base.py
index 2261cbd..e36217f 100644
--- a/lib/caching/base.py
+++ b/lib/caching/base.py
@@ -77,15 +77,7 @@ class CacheMachine(object):
def query_key(self):
"""Generate the cache key for this query."""
- key = '%s:%s' % (translation.get_language(), self.query_string)
-
- # memcached keys must be < 250 bytes and w/o whitespace, but it's nice
- # to see the keys when using locmem.
- if 'memcached' in cache.scheme:
- return '%s%s' % (settings.CACHE_PREFIX,
- hashlib.md5(key).hexdigest())
- else:
- return '%s%s' % (settings.CACHE_PREFIX, key)
+ return make_key('qs:%s' % self.query_string)
def __iter__(self):
try:
@@ -201,3 +193,15 @@ class CachingRawQuerySet(models.query.RawQuerySet):
for obj in CacheMachine(sql, iterator):
yield obj
raise StopIteration
+
+
+def make_key(k):
+ """Generate the full key for ``k``, with a prefix and locale."""
+ lang = translation.get_language()
+ key = '%s:%s:%s' % (settings.CACHE_PREFIX, lang, k)
+ # memcached keys must be < 250 bytes and w/o whitespace, but it's nice
+ # to see the keys when using locmem.
+ if 'memcached' in cache.scheme:
+ return hashlib.md5(key).hexdigest()
+ else:
+ return key