Python 仅为读取已保存的结果激活Dask缓存
我想知道是否可以停用Dask缓存以保存新值,而不是读取已缓存的值 例如,我运行以下代码,只计算一次Python 仅为读取已保存的结果激活Dask缓存,python,caching,dask,Python,Caching,Dask,我想知道是否可以停用Dask缓存以保存新值,而不是读取已缓存的值 例如,我运行以下代码,只计算一次a,然后检索保存的值: import dask from dask.cache import Cache cache = Cache(2e9) cache.register() @dask.delayed def add(i): print("Executed") return i+1 a = add(1) print(a.compute()) print(
a
,然后检索保存的值:
import dask
from dask.cache import Cache
cache = Cache(2e9)
cache.register()
@dask.delayed
def add(i):
print("Executed")
return i+1
a = add(1)
print(a.compute())
print(a.compute())
执行
二,
二,
如果然后调用cache.unregister
我会避免保存b
的结果,但当我再次调用a.compute
时,会执行函数add
:
cache.unregister()
b = add(2)
print(b.compute())
执行
三,
执行
二,
{'add-f0a48927-5f2d-4995-b53f-34630d5c944e':2}
因此,我想知道是否可以将缓存配置为从a.compute()
读取结果,但不从b.compute()
保存新结果。我需要一个全局选项,如cache.unregister()
,因为我正在处理一个大型库,无法逐个元素进行操作
谢谢
print(a.compute())
print(cache.cache.data)