我使用ttl_cache()
中的cachetools.func
使用此功能:
import cachetools.func
class Test:
@cachetools.func.ttl_cache(maxsize=128, ttl=10*60) # <-- This cache is temporal stored for 10min
def df(self):
print('Executing')
return 'Result'
如果我两次运行此函数,我将得到:
test = Test()
test.df()
# Executing
# Result
test.df()
# Result
现在我需要在每次运行代码之间保存此缓存,我知道我可以使用一些自定义装饰器将其与pickle一起保存到磁盘,但是我需要将缓存临时保存x次,所以我想知道是否存在调用ttl_cache
对象之后将其保存到磁盘或类似物中的任何方法。