David Novakovic committed 1ba0ed5

Lets try and shorten cache keys.

Comments (0)

Files changed (1)


 from django.utils.functional import wraps
 from cache_utils.utils import _cache_key, _func_info, _func_type, sanitize_memcached_key
 from django.conf import settings
+import hashlib
     timeout = settings.CACHES['default']['TIMEOUT']
     timeout = 300
+def md5_string(string):
+    m = hashlib.md5()
+    m.update(string)
+    return m.digest()
 def cached(timeout=timeout, group=None):
     """ Caching decorator. Can be applied to function, method or classmethod.
             if not hasattr(wrapper, '_full_name'):
                 name, _args = _func_info(func, args)
                 wrapper._full_name = name
+            cache_key_kwargs = md5_string(repr(kwargs)).encode('base64').strip()
+            cache_key_args = md5_string(repr(args)).encode('base64').strip()
             # try to get the value from cache
-            key = get_key(wrapper._full_name, func_type, args, kwargs)
+            key = get_key(wrapper._full_name, func_type, cache_key_args, cache_key_kwargs)
             value = cache.get(key, **backend_kwargs)
             # in case of cache miss recalculate the value and put it to the cache