src/hdalab/utils.py
author rougeronj
Fri, 12 Dec 2014 11:04:02 +0100
changeset 404 f6b3ecaa3c58
parent 345 7bc38c7d6cf9
child 462 df8b3b49e81c
permissions -rw-r--r--
Merge with 4b3a444be84a9edd2f326ed9fe82895a53a66712

# -*- coding: utf-8 -*-
'''
Created on Mar 13, 2012

@author: ymh and tc
'''
from django.core.cache import cache
from django.utils.encoding import smart_str
import hashlib
import re

import logging
logger = logging.getLogger(__name__)


def fix_cache_key(key):
    cache_key = re.sub(r'\s+', '-', key)
    cache_key = smart_str(cache_key)
    if len(cache_key) > (250-(2+len(cache.key_prefix)+len(str(cache.version)))-33):
        cache_key = cache_key[:(250-(2+len(cache.key_prefix)+len(str(cache.version)))-33)] + '-' + hashlib.md5(cache_key).hexdigest()
    return cache_key