在 Python 中,lru_cache
是一个装饰器,用于添加缓存功能以提高函数的性能。如果你想清除或者删除 lru_cache
中的缓存,有几种方法可以做到:
-
手动清除缓存:
lru_cache
对象有一个方法叫做cache_clear()
,可以手动清除所有缓存。- 示例:
@lru_cache(maxsize=128) def some_function(x): # function body return result # 清除缓存 some_function.cache_clear<