Bird
0
0

You want to cache responses for a controller but exclude caching for a specific method. How can you achieve this with CacheInterceptor?

hard📝 Application Q8 of 15
NestJS - Interceptors
You want to cache responses for a controller but exclude caching for a specific method. How can you achieve this with CacheInterceptor?
AApply CacheInterceptor globally and use @CacheKey() with a unique key on methods to exclude caching.
BApply CacheInterceptor globally and override the method with @UseInterceptors(CacheInterceptor) and set skipCache flag.
CApply CacheInterceptor globally and use @UseInterceptors(ExcludeCacheInterceptor) on the method to skip caching.
DApply CacheInterceptor globally and use @CacheTTL(0) on the method to disable caching for it.
Step-by-Step Solution
Solution:
  1. Step 1: Understand CacheTTL decorator

    @CacheTTL(0) disables caching for the decorated method by setting time-to-live to zero.
  2. Step 2: Evaluate other options

    Apply CacheInterceptor globally and use @CacheKey() with a unique key on methods to exclude caching misuses @CacheKey. Apply CacheInterceptor globally and use @UseInterceptors(ExcludeCacheInterceptor) on the method to skip caching mentions a non-existent ExcludeCacheInterceptor. Apply CacheInterceptor globally and override the method with @UseInterceptors(CacheInterceptor) and set skipCache flag is invalid syntax.
  3. Final Answer:

    Apply CacheInterceptor globally and use @CacheTTL(0) on the method to disable caching for it. -> Option D
  4. Quick Check:

    Use @CacheTTL(0) to skip caching on specific methods [OK]
Quick Trick: Use @CacheTTL(0) to disable caching on a method [OK]
Common Mistakes:
  • Trying to exclude caching with @CacheKey
  • Assuming a special exclude interceptor exists
  • Overriding CacheInterceptor incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes