python - 重置 lru_cache 中的缓存

标签 python python-3.x caching

<分区>

有什么方法可以覆盖 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/

相关文章:

caching - 具有可变参数顺序的 Nginx 缓存

jquery - jQuery $(this) 是否需要缓存

php - 有人将数据库数据存储在 PHP $_SESSION 中吗?

python - 如何按日期对条目进行分组并计算百分比

python - Project Euler 37 的 Python 列表循环

python - 过滤 Python 输出

python - zlib 模块是否释放 Python 3 中的全局解释器锁(GIL)?

python-3.x - peewee可以新建一个MySQL数据库吗

python - SSH连接成功后执行命令

python-3.x - discord.py-需要帮助才能使用cog_command_error