mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-10 21:53:12 +00:00
parent
024676f6e2
commit
709513db65
1 changed files with 6 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
from __future__ import unicode_literals
|
||||
from hashlib import sha1
|
||||
from time import time
|
||||
from types import NoneType
|
||||
|
||||
import django
|
||||
from django.db import connections
|
||||
|
|
@ -13,6 +14,7 @@ if DJANGO_GTE_1_7:
|
|||
from django.utils.module_loading import import_string
|
||||
else:
|
||||
from django.utils.module_loading import import_by_path as import_string
|
||||
from django.utils.six import text_type, binary_type
|
||||
|
||||
from .settings import cachalot_settings
|
||||
from .signals import post_invalidation
|
||||
|
|
@ -22,6 +24,8 @@ class UncachableQuery(Exception):
|
|||
pass
|
||||
|
||||
|
||||
CACHABLE_PARAM_TYPES = (bool, int, binary_type, text_type, NoneType)
|
||||
|
||||
def get_query_cache_key(compiler):
|
||||
"""
|
||||
Generates a cache key from a SQLCompiler.
|
||||
|
|
@ -36,6 +40,8 @@ def get_query_cache_key(compiler):
|
|||
:rtype: str
|
||||
"""
|
||||
sql, params = compiler.as_sql()
|
||||
if any(p.__class__ not in CACHABLE_PARAM_TYPES for p in params):
|
||||
raise UncachableQuery
|
||||
cache_key = '%s:%s:%s' % (compiler.using, sql, params)
|
||||
return sha1(cache_key.encode('utf-8')).hexdigest()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue