<分区>
有什么方法可以覆盖 python 中的 lru_cache
吗?
特别是如果我有这样的功能:
import functools
@functools.lru_cache(maxsize=None)
def function_of_interest(variables):
...
return(processed_values)
是否可以重置缓存,从而运行函数?
<分区>
有什么方法可以覆盖 python 中的 lru_cache
吗?
特别是如果我有这样的功能:
import functools
@functools.lru_cache(maxsize=None)
def function_of_interest(variables):
...
return(processed_values)
是否可以重置缓存,从而运行函数?
最佳答案
Is is possible to reset the cache, and hence re-run the function?
如果我的理解是正确的,你可以在装饰函数上使用cache_clear
。如果您通过运行它填充了缓存,这会为您清除所有指示器,即:
function_of_interest.cache_clear()
应该导致 cache_info
为:
CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)
关于python - 重置 lru_cache 中的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40010815/