Complete the code to import the caching module in a NestJS app.
import { [1] } from '@nestjs/cache-manager';
The CacheModule is the built-in module in NestJS used to enable caching features.
Complete the code to register the CacheModule globally in the app module.
@Module({
imports: [[1].register()],
})
export class AppModule {}Using CacheModule.register() sets up caching globally in the NestJS app.
Fix the error in the method decorator to enable caching for a controller route.
@[1] @Get('data') getData() { return this.service.getData(); }
The correct decorator to enable caching on a route is @Cacheable without parentheses.
Fill both blanks to inject the cache manager and use it to set a cache value.
constructor(@Inject([1]) private cacheManager: [2]) {} async cacheData(key: string, value: any) { await this.cacheManager.set(key, value); }
Inject the cache manager token CACHE_MANAGER and type it as CacheManager to use caching methods.
Fill the blank to create a cache interceptor and apply it to a controller method.
@UseInterceptors([1]) @Get('info') async getInfo() { const data = await this.service.fetchInfo(); return data; }
The CacheInterceptor is used to automatically cache responses of controller methods.