Replies: 1 comment
|
确认下,当前 v4 的行为是这样的:
如果要实现「内存短、Redis 长」的策略,现阶段可以把 ttl 配在各自的子 cache 上,然后调用时不要传第三个参数,例如: memoryCaching: {
store: "memory",
options: { ttl: 60_000 },
},
redisCaching: {
store: createRedisStore("default"),
options: { ttl: 600_000 },
},
multiCaching: {
store: ["memoryCaching", "redisCaching"],
},然后: await multiCaching.set("key", value);这样每一层会使用自己的默认 ttl。你提到的数组/对象 ttl 属于新能力,可以作为后续增强考虑;实现时需要同步改类型定义和 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Describe the problem(描述问题)
问题描述
在使用
@midwayjs/cache-manager配置「内存 + Redis」多级缓存时,发现以下问题:multiCaching级别的options配置不生效示例配置中
multiCaching.options.ttl: 100会被完全忽略,写与不写效果一致。Redis 层 TTL 单位是毫秒
写入 Redis 时使用毫秒(底层命令为
PX),与常见的「秒」单位容易混淆,建议在文档中明确说明。multiCaching.set/mset传 TTL 时,各缓存层过期时间一致通过
set(key, value, ttl)传入的 ttl 会被透传给所有缓存层,无法实现「内存层短期、Redis 层长期」的经典多级缓存策略。最小复现
All reactions