0
0
NestJSframework~5 mins

Cache interceptor in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Cache Interceptor in NestJS?
A Cache Interceptor in NestJS is a tool that automatically stores the response of a request so that future requests can get the stored response quickly without running the full logic again.
Click to reveal answer
intermediate
How do you enable caching globally in a NestJS application?
You enable caching globally by importing and configuring CacheModule in the root module's imports array, and providing { provide: APP_INTERCEPTOR, useClass: CacheInterceptor } in the providers array.
Click to reveal answer
intermediate
Which decorator is used to disable caching on a specific route in NestJS?
The @CacheKey() decorator sets a custom cache key, but to disable caching on a route, you use the @CacheTTL(0) decorator or avoid applying the CacheInterceptor on that route.
Click to reveal answer
beginner
What is the role of CacheModule in NestJS caching?
CacheModule provides the caching functionality and configuration, like setting the store type (memory, redis), default TTL (time to live), and other options for caching in NestJS.
Click to reveal answer
intermediate
How does CacheInterceptor decide when to return cached data?
CacheInterceptor checks if a cached response exists for the request key. If yes, it returns the cached data immediately. If not, it runs the handler, caches the response, then returns it.
Click to reveal answer
What does CacheInterceptor do in NestJS?
AStores and returns cached responses automatically
BHandles user authentication
CManages database connections
DFormats HTTP responses
Which module must be imported to use caching in NestJS?
AHttpModule
BCacheModule
CConfigModule
DAuthModule
How do you apply CacheInterceptor globally in NestJS?
AUse @GlobalCache() decorator
BAdd CacheInterceptor in controller constructor
CSet cache: true in main.ts
DProvide { provide: APP_INTERCEPTOR, useClass: CacheInterceptor } in AppModule providers
What happens if CacheInterceptor finds no cached data for a request?
AReturns an error
BSkips the request
CExecutes the handler and caches the response
DReturns null
Which decorator can set a custom cache key in NestJS?
A@CacheKey()
B@CacheTTL()
C@CacheDisable()
D@CacheControl()
Explain how CacheInterceptor works in NestJS and how it improves application performance.
Think about how saving answers helps you avoid repeating work.
You got /4 concepts.
    Describe the steps to enable caching globally in a NestJS app using CacheModule and CacheInterceptor.
    Remember the setup involves both module import and interceptor application.
    You got /4 concepts.