Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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