Hashes cache keys for memcached support.

This commit is contained in:
Bertrand Bordage 2014-10-06 03:01:46 +02:00
parent 7c5eea8df1
commit 292cbc8bdc

View file

@ -3,6 +3,7 @@
from __future__ import unicode_literals
from collections import defaultdict, Iterable
from functools import wraps
from hashlib import md5
import re
from django.conf import settings
@ -30,6 +31,10 @@ PATCHED = False
MISS_VALUE = '[[Missing cache key]]'
def _get_query_cache_key(compiler):
return md5('%s:%s' % compiler.as_sql()).hexdigest()
def _get_tables(query):
"""
Returns a ``set`` of all database table names used by ``query``.
@ -175,7 +180,7 @@ def _patch_orm_read():
return original(compiler, *args, **kwargs)
try:
cache_key = compiler.as_sql()
cache_key = _get_query_cache_key(compiler)
except EmptyResultSet:
return original(compiler, *args, **kwargs)