0
0
NestJSframework~5 mins

Cache decorators in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Cacheable() decorator in NestJS?
The @Cacheable() decorator marks a method so that its result is stored in cache. When the method is called again with the same arguments, the cached result is returned instead of running the method again, improving performance.
Click to reveal answer
intermediate
How does the @CacheEvict() decorator work in NestJS?
The @CacheEvict() decorator is used to remove specific cache entries when a method is called. This helps keep the cache updated by deleting stale data after changes like updates or deletes.
Click to reveal answer
intermediate
Explain the role of the @CachePut() decorator in NestJS.
The @CachePut() decorator updates the cache with the method's result every time the method is called, regardless of whether the cache already has a value. It is useful for refreshing cache data.
Click to reveal answer
beginner
What is the default cache store used by NestJS cache decorators?
By default, NestJS uses an in-memory cache store for caching. This means cached data is stored in the server's memory and is lost when the server restarts.
Click to reveal answer
intermediate
Why is it important to use cache decorators with proper cache keys?
Proper cache keys ensure that cached data is correctly identified and retrieved. Without unique keys, different method calls might overwrite each other's cache or return wrong data.
Click to reveal answer
Which NestJS cache decorator stores the method result only if it is not already cached?
A@Cacheable()
B@CacheEvict()
C@CachePut()
D@CacheClear()
What does the @CacheEvict() decorator do?
AUpdates cache without checking
BStores method result in cache
CRemoves cache entries
DDisables caching for a method
If you want to refresh cache data every time a method runs, which decorator should you use?
A@CachePut()
B@CacheEvict()
C@Cacheable()
D@CacheDisable()
What happens to the default in-memory cache when the NestJS server restarts?
ACache persists on disk
BCache is cleared
CCache is backed up automatically
DCache is sent to clients
Why should cache keys be unique for different method calls?
ATo speed up method execution
BTo encrypt cached data
CTo disable caching
DTo prevent cache overwriting
Describe how you would use cache decorators in NestJS to improve performance of a data fetching method.
Think about storing, updating, and clearing cache for data methods.
You got /4 concepts.
    Explain the difference between @Cacheable(), @CachePut(), and @CacheEvict() decorators in NestJS.
    Focus on when each decorator affects the cache.
    You got /3 concepts.