def get(self, k): """Retrieval command """ if k not in self._buckets: return None now = time() data = self._buckets[k] if data["t"] > now: return data["v"] self.delete(k) return None
def get(self, k): '''Retrieval command ''' if k not in self._buckets: return None now = time() data = self._buckets[k] if data['t'] > now: return data['v'] self.delete(k) return None
def _set(self, k, v): def remove_data(): k = self._timeouts.popleft() del self._buckets[k] if len(self._buckets) >= self._capacity: remove_data() data = {} data["t"] = time() + self._timeout data["v"] = v self._timeouts.append(k) self._buckets[k] = data