Jason Moiron committed bcdb46c

fix for issue #56, save a per-project constant sentinel to the Cache, and treat that value as None for queries which return None, so that they may be cached

Comments (0)

Files changed (2)

 from transaction import TransactionManager
 import django
+from django.conf import settings as django_settings
 from django.core.exceptions import ImproperlyConfigured
 from django.db.models.signals import post_save, post_delete
+# This sentinel is the representation for "None" that johnny will use in
+# memcached.  In order to avoid possible issues with users taking this value
+# and submitting it as data, this sentinel will also include the md5 hash of
+# the project's SECRET KEY, established with ``startproject``
+sentinel = 'dca94c3916af44dc9fa2eebb8fcbf8a9' + md5(django_settings.SECRET_KEY).hexdigest()
 except NameError:
                 signals.qc_hit.send(sender=cls, tables=tables,
                         query=(sql, params, cls.query.ordering_aliases),
                         size=len(val), key=key)
+                if val is sentinel:
+                    return None
                 return val
             signals.qc_miss.send(sender=cls, tables=tables,
                 #todo - create a smart iterable wrapper
                 val = list(val)
             if key is not None:
-                self.cache_backend.set(key, val, settings.MIDDLEWARE_SECONDS, db)
+                self.cache_backend.set(key, val or sentinel, settings.MIDDLEWARE_SECONDS, db)
             return val
         return newfun


         Publisher.objects.filter(title="Doesn't Exist").exists()
         Publisher.objects.filter(title="Doesn't Exist").exists()
-        self.failUnless(len(connection.queries) == 1)
+        self.assertEqual(len(connection.queries), 1)
     def test_basic_querycaching(self):
         """A basic test that querycaching is functioning properly and is