Skip to content

Commit aeac342

Browse files
LaskiVijay Katam
authored and
Vijay Katam
committed
Avoid spurious cache miss when query is empty (vijaykatam#30)
The lines after `if not result_set:` are executed (as if there had been a cache miss) if the key was found but the resulting set was empty (`False` in a boolean context). This changes the line for a explicit comparison with `None` (the response if there's a cache miss).
1 parent 2a5373d commit aeac342

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

django_cache_manager/cache_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def iterator(self):
4747
except EmptyResultSet:
4848
return
4949
result_set = self.cache_backend.get(key)
50-
if not result_set:
50+
if result_set is None:
5151
logger.debug('cache miss for key {0}'.format(key))
5252
result_set = list(super(CachingQuerySet, self).iterator())
5353
self.cache_backend.set(key, result_set)

0 commit comments

Comments
 (0)