def _incr_append(self, key, other): with lockutils.lock(key): timeout, value = self._get_unlocked(key) if value is None: return None ttl = timeutils.utcnow_ts() - timeout new_value = value + other self._set_unlocked(key, new_value, ttl) return new_value
def _purge_expired(self): """Removes expired keys from the cache.""" now = timeutils.utcnow_ts() for timeout in sorted(self._keys_expires.keys()): # NOTE(flaper87): If timeout is greater # than `now`, stop the iteration, remaining # keys have not expired. if now < timeout: break # NOTE(flaper87): Unset every key in # this set from the cache if its timeout # is equal to `timeout`. (The key might # have been updated) for subkey in self._keys_expires.pop(timeout): try: if self._cache[subkey][0] == timeout: del self._cache[subkey] except KeyError: continue