【问题标题】:Nestjs cache-manager setNestjs 缓存管理器集
【发布时间】:2023-01-19 01:45:25
【问题描述】:

如果键已经存在,Nestjs 缓存管理器设置命令是否替换或附加给定值到键? 文档对此不是很清楚

【问题讨论】:

  • 没有“nestjs 缓存管理器”,它只是 cache-manager 东西。然后阅读他们的文档。 npm docs cache-manager
  • 是的,我读过那些,但他们不提供信息。事实上,它们比 NestJS 更加模糊,docs.nestjs.com/techniques/caching

标签: caching nestjs


【解决方案1】:

如果密钥已经存在,cache-maanger 替换该密钥。它不会附加新值。

没错,我没有读过任何明确说明 .set 覆盖以前数据的文档,但您可以查看 package tests。

我已经下载了存储库并创建了一个新的测试,如下所示:

it('should override key', async () => {
  cache = await caching(async (arg?: MemoryConfig) => memoryStore(arg));
  await cache.set(key, value);
  await sleep(20);
  await expect(cache.get(key)).resolves.toEqual(value);
  const newValue = 'newValue'
  await cache.set(key, newValue);
  await sleep(20)
  await expect(cache.get(key)).resolves.toEqual(newValue);
})

我已经覆盖了密钥,结果是新的,没有附加。

【讨论】:

    猜你喜欢
    • 2022-10-16
    • 2021-07-11
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2016-05-05
    相关资源
    最近更新 更多