Created
January 26, 2013 22:38
-
-
Save akx/4645117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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