Skip to content

Instantly share code, notes, and snippets.

@akx
Created January 26, 2013 22:38
Show Gist options
  • Save akx/4645117 to your computer and use it in GitHub Desktop.
Save akx/4645117 to your computer and use it in GitHub Desktop.
class uWSGICacheBackedDict(object):
def __init__(self, prefix=""):
self.prefix = prefix
def __getitem__(self, key):
value = uwsgi.cache_get(self.prefix + str(key))
if value is None:
raise KeyError(key)
return value
def __setitem__(self, key, value):
uwsgi.cache_set(self.prefix + str(key), str(value))
def __delitem__(self, key):
uwsgi.cache_del(self.prefix + str(key))
def get(self, key, default=None):
value = uwsgi.cache_get(self.prefix + str(key))
if value is None:
return default
else:
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment