app/soc/cache/logic.py
changeset 1958 8e8f45dd46e3
parent 1795 336c35c82b87
child 2070 9555be8634a3
--- a/app/soc/cache/logic.py	Fri Mar 20 21:01:49 2009 +0000
+++ b/app/soc/cache/logic.py	Fri Mar 20 21:02:21 2009 +0000
@@ -23,23 +23,33 @@
 
 
 from google.appengine.api import memcache
+from google.appengine.ext import db
 
 import soc.cache.base
 
 
-def key(model, filter):
+def key(model, filter, order):
   """Returns the memcache key for this query.
   """
 
-  return 'query_for_%s_%s' % (repr(model.kind()), repr(filter))
+  new_filter = {}
+
+  for key, value in filter.iteritems():
+    new_value = value.key().name() if isinstance(value, db.Model) else value
+    new_filter[key] = new_value
+
+  return 'query_for_%(kind)s_%(filter)s_%(order)s' % {
+      'kind': repr(model.kind()),
+      'filter': repr(new_filter),
+      'order': repr(order),
+      }
 
 
-def get(model, filter, *args, **kwargs):
+def get(model, filter, order, *args, **kwargs):
   """Retrieves the data for the specified query from the memcache.
   """
 
-  memcache_key = key(model, filter)
-  import logging; logging.info(memcache_key)
+  memcache_key = key(model, filter, order)
   return memcache.get(memcache_key), memcache_key
 
 
@@ -52,7 +62,6 @@
 
   # Store data for fifteen minutes to force a refresh every so often
   retention = 15*60
-
   memcache.add(memcache_key, data, retention)