decorator用具有ttl结果的memoizing可调用函数包装函数。
ttl-cache的Python项目详细描述
TTL缓存
如何使用
pip install ttl-cache
importttl_cache# use ttl_cache directly@ttl_cachedefexpensive_operation(a,b):......returnSOME_RESULTexpensive_operation(xx,yy)expensive_operation(xx,yy)# prefer cached result# ... 60 seconds laterexpensive_operation(xx,yy)# compute again# or@ttl_cache(2.0)# cache the result in the next 2 seconds, default is 60.0 secondsdefexpensive_operation(a,b):......