Clean-ish memcached key generation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django.utils.hashcompat import md5_constructor

drop_chars = ''.join(['%c' % c for c in range(32)]) + ' '

def cache_key_clean(value):
    """
    Make a key of the first up to 228 valid characters of the value,
    appended with the md5 of the whole value.
    """
    md5_hash = md5_constructor(value).hexdigest()
    return ''.join([value.translate(None,drop_chars)[:228], md5_hash])

More like this

  1. Function decorator for caching function results in local memory by bikeshedder 1 year, 6 months ago
  2. Scoped Cache Compatible with Django Caching Helpers by axiak 6 years, 1 month ago
  3. Method Caching by bryanhelmig 2 years, 9 months ago
  4. Alphabetic filter for admin by semente 5 years, 7 months ago
  5. Safer cache key generation by cmheisel 5 years, 4 months ago

Comments

(Forgotten your password?)