我有一个 python 函数,它根据传递的参数缓存结果。问题是,fval()可以根据其他因素返回不同的值。但是test()仍然给我发送了陈旧的价值观。我如何确保参数v从中获取最新值fval()
@cached(60*5)
def test(a,v=fval()):
print "inside function"
return a,v
r = test(2)
inside test function
print r
(2, 5)
print fval()
7
r = test(2) . #This time I am expecting v to be 7, but it isnt
print r
(2,5)
我期待 r 打印 (2,7) 代替。如何确保将最新值作为参数发送到缓存函数?