コード例 #1
0
ファイル: ramlrucache.py プロジェクト: cyplp/modularcache
    def cached(self, func, *args, **kwargs):
        """
        >>> r = RamLRUCache({'size' : 5})
        >>> r._cache =  {'a': {'([1, 2], {})': {'{}': 3}}}
        >>> r.cached('a',[1, 2], {})
        3
        >>> r._order
        ['a||(([1, 2], {}), {})||{}']
        >>> r._cache = {'a': {'([1, 2], {})': {'{}': 3}}, 'c': {'([1, 3], {})': {'{}': 3.1400000000000001}}, 'b': {'([1, 3], {})': {'{}': 66}}}
        >>> r._order = ['a||(([1, 2], {}), {})||{}', 'b||(([1, 3], {}), {})||{}', 'c||(([1, 3], {}), {})||{}']
        >>> r._order
        ['a||(([1, 2], {}), {})||{}', 'b||(([1, 3], {}), {})||{}', 'c||(([1, 3], {}), {})||{}']
        >>> r.cached('a',[1, 2], {})
        3
        >>> r._order
        ['b||(([1, 3], {}), {})||{}', 'c||(([1, 3], {}), {})||{}', 'a||(([1, 2], {}), {})||{}']
        """
        
        key = self._computeKey(func, args, kwargs )

        if key in self._order:
            self._order.remove(key)
           
        self._order.append(key)
        
        return RamCache.cached(self, func, *args, **kwargs)