skoczen committed 8d37c76

Added JOHNNY_DATABASE_MAPPING setting, to support a shared master/slave queryset cache

Comments (0)

Files changed (2)

         """Returns a key that is standard for a given table name and database alias.
         Total length up to 212 (max for memcache is 250)."""
         table = unicode(table)
+        if db in settings.DATABASE_MAPPING:
+            db = settings.DATABASE_MAPPING[db]
         db = unicode(db)
         if len(table) > 100:
             table = table[0:68] + self.gen_key(table[68:])
     def gen_multi_key(self, values, db='default'):
         """Takes a list of generations (not table keys) and returns a key."""
+        if db in settings.DATABASE_MAPPING:
+            db = settings.DATABASE_MAPPING[db]
         if db and len(db) > 100:
             db = db[0:68] + self.gen_key(db[68:])
         return '%s_%s_multi_%s' % (self.prefix, db, self.gen_key(*values))
     def sql_key(self, generation, sql, params, order, result_type, using='default'):
         """Return the specific cache key for the sql query described by the
         pieces of the query and the generation key."""
+        if using in settings.DATABASE_MAPPING:
+            using = settings.DATABASE_MAPPING[using]
         # these keys will always look pretty opaque
         key = '%s_%s_query_%s.%s' % (self.prefix, using, generation, self.keygen.gen_key(sql, params,
                 order, result_type))
         from django.db.models.sql.constants import MULTI
         from django.db.models.sql.datastructures import EmptyResultSet
         def newfun(cls, *args, **kwargs):
             if args:


 CACHES = getattr(settings, 'CACHES', {})
 def _get_backend():
     """Returns the actual django cache object johnny is configured to use.
     This relies on the settings only;  the actual active cache can