src/hdalab/utils.py
changeset 345 7bc38c7d6cf9
parent 319 fef4317b915f
child 462 df8b3b49e81c
equal deleted inserted replaced
344:1473ba25af1f 345:7bc38c7d6cf9
     4 
     4 
     5 @author: ymh and tc
     5 @author: ymh and tc
     6 '''
     6 '''
     7 from django.core.cache import cache
     7 from django.core.cache import cache
     8 from django.utils.encoding import smart_str
     8 from django.utils.encoding import smart_str
     9 import md5
     9 import hashlib
    10 import re
    10 import re
    11 
    11 
    12 import logging
    12 import logging
    13 logger = logging.getLogger(__name__)
    13 logger = logging.getLogger(__name__)
    14 
    14 
    15 
    15 
    16 def fix_cache_key(key):
    16 def fix_cache_key(key):
    17     cache_key = re.sub(r'\s+', '-', key)
    17     cache_key = re.sub(r'\s+', '-', key)
    18     cache_key = smart_str(cache_key)
    18     cache_key = smart_str(cache_key)
    19     if len(cache_key) > (250-(2+len(cache.key_prefix)+len(str(cache.version)))-33):
    19     if len(cache_key) > (250-(2+len(cache.key_prefix)+len(str(cache.version)))-33):
    20         cache_key = cache_key[:(250-(2+len(cache.key_prefix)+len(str(cache.version)))-33)] + '-' + md5.new(cache_key).hexdigest()
    20         cache_key = cache_key[:(250-(2+len(cache.key_prefix)+len(str(cache.version)))-33)] + '-' + hashlib.md5(cache_key).hexdigest()
    21     return cache_key
    21     return cache_key
    22         
    22         
    23         
    23