相关疑难解决方法(0)

如何在python @ functools.lru_cache上使用cache_clear()

文件说明:

装饰器还提供cache_clear()清除或使缓存无效的功能.

它没有提供有关如何使用的任何示例或指导 cache_clear()

我有两个问题:

  • 如何cache_clear()从不同的功能运行?
  • 如果我cache_clear()有条件地将一个调用放在正在缓存的函数中,它会被执行吗?

python python-3.x

38
推荐指数
2
解决办法
1万
查看次数

清除@property方法python的缓存

我在一个类中有一些属性方法,我想在某个时候清除此属性的缓存。

范例:

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()适用于函数,但不适用于属性方法。有什么办法吗?

python python-3.x

2
推荐指数
1
解决办法
201
查看次数

标签 统计

python ×2

python-3.x ×2