Complete the code to import the CacheInterceptor from NestJS.
import { [1] } from '@nestjs/common';
The CacheInterceptor is imported from @nestjs/common to enable caching behavior in controllers or routes.
Complete the code to apply the CacheInterceptor globally using app.useGlobalInterceptors.
app.[1](new CacheInterceptor());To apply caching globally, you use useGlobalInterceptors with an instance of CacheInterceptor.
Fix the error in the code to enable caching on a controller method using the CacheInterceptor.
@UseInterceptors([1]) @Get('data') getData() { return { message: 'Hello' }; }
The @UseInterceptors decorator requires the CacheInterceptor to enable caching on the method.
Fill both blanks to configure the CacheModule with a TTL of 10 seconds.
imports: [CacheModule.[1]({ ttl: [2] })]
The CacheModule is configured with register method and a TTL (time to live) of 10 seconds.
Fill both blanks to create a custom cache interceptor class that extends CacheInterceptor and overrides trackBy method to cache only GET requests.
export class CustomCacheInterceptor extends CacheInterceptor { trackBy(context: ExecutionContext): string | undefined { const request = context.switchToHttp().getRequest(); if (request.method !== [1]) { return undefined; } return super.[2](context); } }
The custom interceptor checks if the HTTP method is 'GET' to cache only GET requests. It overrides the trackBy method to customize cache key generation.