Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Issue #2 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions sql_caching/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
'''
from threading import local
import itertools
from django.utils.deprecation import MiddlewareMixin
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.datastructures import EmptyResultSet
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE


_thread_locals = local()


Expand All @@ -30,7 +30,7 @@ def execute_sql_cache(self, *args, **kwargs):
if hasattr(_thread_locals, 'query_cache'):

sql = get_sql(self) # ('SELECT * FROM ...', (50)) <= sql string, args tuple
if sql[0][:6].upper() == 'SELECT':
if sql[0].upper().lstrip().startswith('SELECT'):

# uses the tuple of sql + args as the cache key
if sql in _thread_locals.query_cache:
Expand All @@ -57,7 +57,7 @@ def execute_sql_cache(self, *args, **kwargs):
return self._execute_sql(*args, **kwargs)


class QueryCacheMiddleware(object):
class QueryCacheMiddleware(MiddlewareMixin):
def process_request(self, request):
_thread_locals.query_cache = {}

Expand Down