Exemple #1
0
    def putInCache(self, func, result, *args, **kwargs):
        """
        >>> r = RamLRUCache({'size' : 5})
        >>> r.putInCache('a', 3, [1, 2], {})
        3
        >>> r._order
        ['a||(([1, 2], {}), {})||{}']
        >>> r.putInCache('b', 66, [1, 3], {})
        66
        >>> r.putInCache('c', 3.14, [1, 3], {})
        3.1400000000000001
        >>> r._order
        ['a||(([1, 2], {}), {})||{}', 'b||(([1, 3], {}), {})||{}', 'c||(([1, 3], {}), {})||{}']
        >>> r._cache
        {'a': {'([1, 2], {})': {'{}': 3}}, 'c': {'([1, 3], {})': {'{}': 3.1400000000000001}}, 'b': {'([1, 3], {})': {'{}': 66}}}
        """

        key = self._computeKey(func, args, kwargs )

        self._order.append(key)
        if len(self._order) >= self._size:
            tmp = self._order.pop(0).split('||')
            del(_cache[tmp[0]][tmp[1]][tmp[2]])

        return RamCache.putInCache(self, func, result, *args, **kwargs)