在lru_cache中重置缓存

时间:2016-10-13 01:21:50

标签: python python-3.x caching

有没有办法在python中覆盖lru_cache

具体来说,如果我有一个功能,如:

  import functools

  @functools.lru_cache(maxsize=None)
  def function_of_interest(variables):

       ...
       return(processed_values)

是否可以重置缓存,从而运行该函数?

1 个答案:

答案 0 :(得分:2)

  

是否可以重置缓存,从而重新运行该功能?

如果我的理解是正确的,你可以在装饰函数上使用cache_clear。如果您通过运行缓存来填充缓存,则会清除所有指标,即:

function_of_interest.cache_clear()

应该导致cache_info

CacheInfo(hits=0, misses=0, maxsize=None, currsize=0)
相关问题