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.
