django-cachalot
django-cachalot copied to clipboard
SUPPORTED_CACHE_BACKENDS should support extending base classes
We use a custom cache backend which just extends the base one but provides some extra functionality.
For example:
class MemcachedCache(PyLibMCCache):
"""
Extends PyLibMCCache to set options and prevent close
"""
def __init__(self, server, params, username=None, password=None):
# ensure options is lower case
try:
params['OPTIONS'] = {k.lower(): v for k, v in params['OPTIONS'].iteritems()}
# turn binary back to caps, but default it to true
params['BINARY'] = params['OPTIONS'].pop('binary', 1)
except KeyError:
pass
super(MemcachedCache, self).__init__(server, params, username, password)
def close(self, **kwargs):
"""
Override close to keep connection open
"""
pass
the list is fixed like so:
SUPPORTED_CACHE_BACKENDS = {
'django.core.cache.backends.dummy.DummyCache',
'django.core.cache.backends.locmem.LocMemCache',
'django.core.cache.backends.filebased.FileBasedCache',
'django_redis.cache.RedisCache',
'django.core.cache.backends.memcached.MemcachedCache',
'django.core.cache.backends.memcached.PyLibMCCache',
}
A small fix could be to check using isinstance perhaps ? and then it should just auto work for people who have custom but extended supported cache backends.
thanks
Next version, I'll include a method of flexibility for this.