我知道cache_clear。但是我想知道如何清除单个调用的缓存。看到cache_clear不接受一个论点,我认为唯一的方法是直接弄乱底层字典。会产生什么副作用(如果有的话)?
目标是实现以下目标
from functools import lru_cache
@lru_cache()
def f(x):
print('called with ', x)
f(1)
f.cache_clear(1) # obviously does not work
f(1)
Run Code Online (Sandbox Code Playgroud)
随着输出
called with 1
called with 1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |