|
154
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
''' |
|
|
3 |
Created on Mar 13, 2012 |
|
|
4 |
|
|
|
5 |
@author: ymh |
|
|
6 |
''' |
|
|
7 |
from django.core.cache import cache |
|
|
8 |
from django.utils.encoding import smart_str |
|
|
9 |
import md5 |
|
|
10 |
import re |
|
|
11 |
|
|
|
12 |
|
|
|
13 |
def fix_cache_key(key): |
|
|
14 |
cache_key = re.sub(r'\s+', '-', key) |
|
|
15 |
cache_key = smart_str(cache_key) |
|
|
16 |
if len(cache_key) > (250-(2+len(cache.key_prefix)+len(str(cache.version)))-33): |
|
|
17 |
cache_key = cache_key[:(250-(2+len(cache.key_prefix)+len(str(cache.version)))-33)] + '-' + md5.new(cache_key).hexdigest() |
|
|
18 |
return cache_key |