def set(self, key, value, time=0, min_compress_len=0): """Sets the value for a key.""" timeout = 0 if time != 0: timeout = timeutils.utcnow_ts() + time self.cache[key] = (timeout, value) return True
def get(self, key): """Retrieves the value for a key or None. This expunges expired keys during each get. """ now = timeutils.utcnow_ts() for k in self.cache.keys(): (timeout, _value) = self.cache[k] if timeout and now >= timeout: del self.cache[k] return self.cache.get(key, (0, None))[1]