File tree 2 files changed +56
-63
lines changed
2 files changed +56
-63
lines changed Original file line number Diff line number Diff line change @@ -748,8 +748,9 @@ def is_namedtuple(cls):
748
748
def flexicache (* funcs , maxsize = 128 ):
749
749
"Like `lru_cache`, but customisable with policy `funcs`"
750
750
import asyncio
751
+ from collections import OrderedDict
751
752
def _f (func ):
752
- cache ,states = {} , [None ]* len (funcs )
753
+ cache ,states = OrderedDict () , [None ]* len (funcs )
753
754
def _cache_logic (key , execute_func ):
754
755
if key in cache :
755
756
result ,states = cache [key ]
@@ -763,8 +764,7 @@ def _cache_logic(key, execute_func):
763
764
cache [key ] = cache .pop (key )
764
765
return result
765
766
cache [key ] = (newres , [f (None ) for f in funcs ])
766
- # remove the oldest item when cache overflows
767
- if len (cache ) > maxsize : del cache [next (iter (cache ))]
767
+ if len (cache ) > maxsize : cache .popitem (last = False )
768
768
return newres
769
769
770
770
@wraps (func )
You can’t perform that action at this time.
0 commit comments