Bird
0
0

Which of the following is the correct way to apply the CacheInterceptor to a controller method in NestJS?

easy📝 Syntax Q12 of 15
NestJS - Interceptors
Which of the following is the correct way to apply the CacheInterceptor to a controller method in NestJS?
AAdd CacheInterceptor in the constructor of the controller
B@Cacheable() decorator on the method
C@UseInterceptors(CacheInterceptor) above the method
DUse @CacheInterceptor() as a method parameter
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to apply interceptors in NestJS

    Interceptors are applied using the @UseInterceptors() decorator above methods or controllers.
  2. Step 2: Check each option

    Only @UseInterceptors(CacheInterceptor) above the method uses the correct decorator syntax. Options B, C, and D are invalid or do not exist in NestJS.
  3. Final Answer:

    @UseInterceptors(CacheInterceptor) above the method -> Option C
  4. Quick Check:

    UseInterceptors decorator = A [OK]
Quick Trick: Use @UseInterceptors(CacheInterceptor) to apply caching [OK]
Common Mistakes:
  • Using non-existent @Cacheable decorator
  • Trying to inject interceptor in constructor
  • Passing interceptor as method parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes