Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion johnny/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ def __init__(self, cache_backend=None, keyhandler=None, keygen=None):
self.kg_class, self.prefix)
self._patched = getattr(self, '_patched', False)

def is_count(self, sql):
if "COUNT" in sql:
return True
return False

def _monkey_select(self, original):
from django.db.models.sql.constants import MULTI
from django.db.models.sql.datastructures import EmptyResultSet
Expand Down Expand Up @@ -368,7 +373,9 @@ def newfun(cls, *args, **kwargs):
#no longer lazy...
#todo - create a smart iterable wrapper
val = list(val)
if key is not None:
#if COUNT cache is disabled, this is a query with `COUNT` in it, and `val` is a number,
#don't touch the cache.
if key is not None and not (settings.DISABLE_COUNT_CACHE and self.is_count(sql)) and not (val and type(val) == list and type(val[0]) in (long, int)):
if not val:
self.cache_backend.set(key, no_result_sentinel, settings.MIDDLEWARE_SECONDS, db)
else:
Expand Down
1 change: 1 addition & 0 deletions johnny/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.cache import get_cache, cache

DISABLE_QUERYSET_CACHE = getattr(settings, 'DISABLE_QUERYSET_CACHE', False)
DISABLE_COUNT_CACHE = getattr(settings, 'JOHNNY_DISABLE_COUNT_CACHE', False)

DEFAULT_BLACKLIST = ['south_migrationhistory']

Expand Down