Twitter 上看到 Python 3 內建的 lru_cache()
:
One of my favorite Python 3 builtins is functools.lru_cache(): with a simple decorator, repeated function calls become O(1) table lookups. https://t.co/ORphGWvkCz pic.twitter.com/NmYVIxO9mE
— Jake VanderPlas (@jakevdp) August 8, 2018
從文件上可以看到預設值是 128 個:
@functools.lru_cache(maxsize=128, typed=False)
tweet 裡面有討論到 memory leak 的問題可以看一下,不過如果是拿來寫工具的話,應該不會有什麼問題...