cache backends that are primarily for local dev should enforce same key restrictions as memcached
|Reported by:||Owned by:||Carl Meyer|
|Component:||Core (Cache system)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Using a locmem:// or postgres cache backend, I can generate a cache key using the following expression:
repr(f.__module__) + repr(f.__name__) + repr(args) + repr(kwargs)
but if I configure memcached, it fails silently, causing an empty page to be sent to the client.
I have confirmed this is the source of the problem by generating an md5.hexdigest of the above key - in which case, memcached works correctly.
I have included the context for the above key, in case it is relevant. It is a decorator method which caches the return value of an arbitrary function, assuming its value depeonds solely on its parameters, and that the method never returns None
from django.core.cache import cache as _djcache def cache(seconds = 3600): def doCache(f): def x(*args, **kwargs): key = md5(repr(f.__module__) + repr(f.__name__) + repr(args) + repr(kwargs)).hexdigest() result = _djcache.get(key) if result is None: result = f(*args, **kwargs) _djcache.set(key, result, seconds) return result return x return doCache
Change History (20)
comment:10 Changed 7 years ago by
|Summary:||memcached does not support arbitrary string keys → cache backends that are primarily for local dev should enforce same key restrictions as memcached|