Created
September 16, 2013 12:39
-
-
Save xfenix/6580181 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CacheGroup(object): | |
ttl = 3600 | |
initial = 1 | |
group = '' | |
def __init__(self, group, ttl): | |
self.group = group | |
self.ttl = ttl | |
def key(self, key): | |
postfix = cache.get(self.group) | |
if not postfix: | |
cache.set(self.group, self.initial) | |
postfix = self.initial | |
return key + str(postfix) | |
def set(self, key, value): | |
cache.set(self.key(key), value, self.ttl) | |
def get(self, key): | |
return cache.get(self.key(key), None) | |
@classmethod | |
def _invalidate(cls, group): | |
number = cache.get(group) | |
if number: | |
cache.set(group, int(number) + 1) | |
@classmethod | |
def invalidate(cls, group=None): | |
cls._invalidate(group) | |
def invalidate2(self): | |
self._invalidate(self.group) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment