如何将临时缓存保存到磁盘?

时间:2020-10-31 19:31:06

标签: python python-3.x caching pickle

我使用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对象之后将其保存到磁盘或类似物中的任何方法。

0 个答案:

没有答案