我正在按照NestJS 文档实现缓存。
为此创建新项目,以便文档示例与此没有区别。
import { CacheModule, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [CacheModule.register()],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)
import { CACHE_MANAGER, Controller, Get, Inject } from '@nestjs/common';
import { Cache } from 'cache-manager';
@Controller()
export class AppController {
constructor(
@Inject(CACHE_MANAGER) private cacheManager: Cache,
) {}
}
Run Code Online (Sandbox Code Playgroud)
@Get()
async getHello(): Promise<string> {
const value: string = await this.cacheManager.get('hello'); …Run Code Online (Sandbox Code Playgroud) nestjs ×1