如何通过缓存管理器检索存储在内存缓存中的所有数据

har*_*bar 2 node.js nestjs

我使用缓存管理器作为内存中数据存储,如文档https://docs.nestjs.com/techniques/caching https://www.npmjs.com/package/cache-manager中所述

有没有可能的方法来检索所有数据作为示例

const value = this.cacheManager.getall();
Run Code Online (Sandbox Code Playgroud)

Sam*_*eer 6

有一个store属性cacheManager,您可以从中获取所有内容keys并获取数据。

@Get('get-all-data')
async getData() {
  //Get all keys
  const keys = await this.cacheManager.store.keys();

  //Loop through keys and get data
  const allData: { [key: string]: any } = {};
  for (const key of keys) {
    allData[key] = await this.cacheManager.get(key);
  }
  return allData;
}
Run Code Online (Sandbox Code Playgroud)