Ever wonder what the heck is going on in your django cache? Ever wish you could clear an entry or two or all? Well I have, and CacheMgr is my answer:
This does not negate the need for proper cache use, but it can be a life saver when you want to update your sites templates, but don’t want to restart the server because people are say, using it to submit proposals before a deadline. This app is not feature complete. Currently only the following cache backends are supported:
- dummy
- simple
- localmem
The remaining backends need to be implemented. The database and file based backends are simple to do, but memcached will take a bit more work. The system is extensible, so you can extend it to work with your own cache backends the same way you can with django’s cache system. All you have to do is extend the base class the same way you would with the django cache system:
class BaseCacheMgr(object):
"""No description has been set.
"""
has_cull = False
scheme = 'unknown'
def __init__(self, cache, host, params):
self.cache = cache
def __iter__(self):
"""Should be overridden to iterate over the cache and return
a dict with the form {'key': key, 'short_key': short_key,
'repr': cache_value,
'expires': datetime_expires, 'expired': False}
"""
raise NotImplementedError
def info(self):
default = (str(self.cache.default_timeout)
if hasattr(self.cache, 'default_timeout') else 'None')
return [{'name': 'Scheme', 'value': self.scheme},
{'name': 'Description', 'value': self.__doc__},
{'name': 'Default Timeout', 'value': default},
{'name': 'Has Cull', 'value': repr(self.has_cull)}]
def clear(self):
raise NotImplementedError
def cull(self):
if not self.has_cull: return
raise NotImplementedError
def delete(self, key):
self.cache.delete(key)
Fairly self explanatory when you look at the image above. Take a look at the simple backend implementation for more details.
Other features that need to be implemented:
- Clear Expired Button
- Paged View (like the admin)
- Sort Table heading links (like the admin)
- Search Fields (like the admin)
- Move the repr/short_key/expires helper code into the base class.

IIUC this will be difficult to implement for memcached, which does not have an API call to list the keys in the cache. The FAQ says this would kill performance:
http://www.socialtext.net/memcached/index.cgi?faq#can_i_iterate_the_items_of_the_memcached_server
Kent,
Yea, that was what I was hinting at when I said ‘memcached will take a bit more work’. I have not found a good solution to a number of memcached issues. It might require comming up with a new memcached backend implementation which caches the keys in a localmem fashion, and have the cachemgr do full page bulk gets. Granted this means that base memcached will still not be supported.