安装包
pip install cachetools
使用示例
from cachetools import TTLCache, cached # 使用 cachetools 的 TTL 缓存(带过期时间)60秒过期 (cache=TTLCache(maxsize=128, ttl=60)) def fibonacci_cachetools_ttl(n): """使用 cachetools TTL 缓存的递归实现""" if n <= 0: return 0 if n == 1: return 1 return fibonacci_cachetools_ttl(n-1) + fibonacci_cachetools_ttl(n-2)