Skip to content

Instantly share code, notes, and snippets.

@xfenix
Created September 16, 2013 12:39
Show Gist options
  • Save xfenix/6580181 to your computer and use it in GitHub Desktop.
Save xfenix/6580181 to your computer and use it in GitHub Desktop.
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