我使用缓存管理器作为内存中数据存储,如文档https://docs.nestjs.com/techniques/caching https://www.npmjs.com/package/cache-manager中所述
有没有可能的方法来检索所有数据作为示例
const value = this.cacheManager.getall();
Run Code Online (Sandbox Code Playgroud)
有一个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)
| 归档时间: |
|
| 查看次数: |
4410 次 |
| 最近记录: |