Skip to content

Commit 9eb2fac

Browse files
committed
Make flexicache LRU instead of FIFO
1 parent ca1b05e commit 9eb2fac

File tree

2 files changed

+86
-58
lines changed

2 files changed

+86
-58
lines changed

fastcore/xtras.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ def _cache_logic(key, execute_func):
763763
cache[key] = cache.pop(key)
764764
return result
765765
cache[key] = (newres, [f(None) for f in funcs])
766-
if len(cache) > maxsize: cache.popitem()
766+
# remove the oldest item when cache overflows
767+
if len(cache) > maxsize: del cache[next(iter(cache))]
767768
return newres
768769

769770
@wraps(func)

0 commit comments

Comments
 (0)