1
+ # -*- coding: utf-8 -*-
1
2
import inspect
2
3
import hashlib
3
4
import logging
@@ -42,11 +43,11 @@ class cache_types(object):
42
43
43
44
cache = caches [CACHE_BACKEND ]
44
45
45
-
46
46
hash_slice = None
47
47
if CACHE_KEY_HASH :
48
48
hash_slice = slice (None , CACHE_KEY_HASH_LENGTH )
49
49
50
+
50
51
def _hash_key_component (s ):
51
52
return hashlib .sha1 (s .encode ('utf-8' )).hexdigest ()[hash_slice ]
52
53
@@ -93,7 +94,7 @@ def get_cache_key(datatable_class, view=None, user=None, **kwargs):
93
94
kwargs_id = _hash_key_component (kwargs_id )
94
95
cache_key += '__kwargs_%s' % (kwargs_id ,)
95
96
96
- log .debug (" Cache key derived for %r: %r (from kwargs %r)" , datatable_class , cache_key , values )
97
+ log .debug (' Cache key derived for %r: %r (from kwargs %r)' , datatable_class , cache_key , values )
97
98
98
99
return cache_key
99
100
@@ -102,12 +103,12 @@ def get_cached_data(datatable, **kwargs):
102
103
""" Returns the cached object list under the appropriate key, or None if not set. """
103
104
cache_key = '%s%s' % (CACHE_PREFIX , datatable .get_cache_key (** kwargs ))
104
105
data = cache .get (cache_key )
105
- log .debug (" Reading data from cache at %r: %r" , cache_key , data )
106
+ log .debug (' Reading data from cache at %r: %r' , cache_key , data )
106
107
return data
107
108
108
109
109
110
def cache_data (datatable , data , ** kwargs ):
110
111
""" Stores the object list in the cache under the appropriate key. """
111
112
cache_key = '%s%s' % (CACHE_PREFIX , datatable .get_cache_key (** kwargs ))
112
- log .debug (" Setting data to cache at %r: %r" , cache_key , data )
113
+ log .debug (' Setting data to cache at %r: %r' , cache_key , data )
113
114
cache .set (cache_key , data )
0 commit comments