feat(cache): 添加自定义TTL支持和内存限制配置

This commit is contained in:
Windpicker-owo
2025-11-02 13:25:39 +08:00
parent 0895d772ac
commit 99785d09ad
4 changed files with 162 additions and 20 deletions

View File

@@ -198,9 +198,12 @@ def cached(
# 执行函数
result = await func(*args, **kwargs)
# 写入缓存注意MultiLevelCache.set不支持ttl参数使用L1缓存的默认TTL
await cache.set(cache_key, result)
logger.debug(f"缓存写入: {cache_key}")
# 写入缓存,传递自定义TTL参数
await cache.set(cache_key, result, ttl=ttl)
if ttl is not None:
logger.debug(f"缓存写入: {cache_key} (TTL={ttl}s)")
else:
logger.debug(f"缓存写入: {cache_key} (使用默认TTL)")
return result