文件说明:
装饰器还提供
cache_clear()清除或使缓存无效的功能.
它没有提供有关如何使用的任何示例或指导 cache_clear()
我有两个问题:
cache_clear()从不同的功能运行?cache_clear()有条件地将一个调用放在正在缓存的函数中,它会被执行吗?我在一个类中有一些属性方法,我想在某个时候清除此属性的缓存。
范例:
class Test():
def __init__(self):
pass
@property
@functools.lru_cache()
def prop(self):
# Compute some stuffs and return complex number
Run Code Online (Sandbox Code Playgroud)
如果我做self.prop.clear_cache(),在这里我得到以下错误信息:
AttributeError: 'numpy.complex128' object has no attribute 'cache_clear'
Run Code Online (Sandbox Code Playgroud)
clear_cache()适用于函数,但不适用于属性方法。有什么办法吗?