Bird
0
0

Identify the error in this NestJS CacheInterceptor usage:

medium📝 Debug Q14 of 15
NestJS - Interceptors
Identify the error in this NestJS CacheInterceptor usage:
import { Controller, Get, UseInterceptors } from '@nestjs/common';
import { CacheInterceptor } from '@nestjs/cache-manager';

@Controller()
export class TestController {
  @UseInterceptors(CacheInterceptor())
  @Get('test')
  test() {
    return 'Test response';
  }
}
ACacheInterceptor should not be called as a function
BMissing CacheModule import in the controller
CMethod test must be async to use CacheInterceptor
DCacheInterceptor must be applied globally, not per method
Step-by-Step Solution
Solution:
  1. Step 1: Check how CacheInterceptor is applied

    CacheInterceptor is a class, not a function, so it should be passed without parentheses to @UseInterceptors().
  2. Step 2: Verify other options

    CacheModule import is required but not shown here (not an error in this snippet). Method does not need to be async. CacheInterceptor can be applied per method.
  3. Final Answer:

    CacheInterceptor should not be called as a function -> Option A
  4. Quick Check:

    Use class name without () = A [OK]
Quick Trick: Pass CacheInterceptor class, not call it as function [OK]
Common Mistakes:
  • Calling CacheInterceptor with parentheses
  • Assuming method must be async
  • Thinking CacheModule import error here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes