gpt4 book ai didi

python lru_cache显式修改

转载 作者:太空宇宙 更新时间:2023-11-03 20:22:13 24 4
gpt4 key购买 nike

假设我有以下功能:

@lru_cache(maxsize=None)
def very_expensive_function(arg):
...

运行时期间,我可以计算某些参数的very_expense_function(不调用它)的结果。是否可以将这些结果注入(inject)到缓存中,而不需要very_expense_function 自己计算出来?

最佳答案

ring还提供修改功能。

import ring

@ring.lru()
def very_expensive_function(arg):
pass

v = very_expensive_function(1)
very_expensive_function.delete(1) # delete cache for 1

# other functions
v = very_expensive_function.execute(1) # run without any cache function
v = very_expensive_function.get(1) # get only if cache exists
v = very_expensive_function.update(1) # force to update
very_expensive_function.set(x, 1) # override cache value without running

查看更多 feature document

关于python lru_cache显式修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58087705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com