0
0
NestJSframework~10 mins

Cache decorators in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to apply the cache decorator to the method.

NestJS
@[1]()
getData() {
  return 'data';
}
Drag options to blanks, or click blank then click option'
ACacheKey
BCacheable
CCacheTTL
DCacheInterceptor
Attempts:
3 left
💡 Hint
Common Mistakes
Using @CacheKey instead of @Cacheable
Using @CacheTTL which sets time but does not enable caching
Using @CacheInterceptor which is for interceptors, not decorators
2fill in blank
medium

Complete the code to set a custom cache key for the method.

NestJS
@Cacheable()
@[1]('custom_key')
fetchItems() {
  return ['item1', 'item2'];
}
Drag options to blanks, or click blank then click option'
ACacheTTL
BCacheInterceptor
CCacheKey
DCacheConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using @CacheTTL which sets time, not key
Using @CacheInterceptor which is unrelated here
Using @CacheConfig which is for global config
3fill in blank
hard

Fix the error in the code to set cache time-to-live (TTL) correctly.

NestJS
@Cacheable()
@[1](3000)
getUsers() {
  return ['user1', 'user2'];
}
Drag options to blanks, or click blank then click option'
ACacheTTL
BCacheKey
CCacheable
DCacheInterceptor
Attempts:
3 left
💡 Hint
Common Mistakes
Using @CacheKey instead of @CacheTTL
Using @Cacheable with a number argument which is invalid
Using @CacheInterceptor which is unrelated
4fill in blank
hard

Fill both blanks to apply caching with a custom key and TTL.

NestJS
@Cacheable()
@[1]('session_data')
@[2](600)
getSession() {
  return { id: 1, user: 'Alice' };
}
Drag options to blanks, or click blank then click option'
ACacheKey
BCacheTTL
CCacheInterceptor
DCacheConfig
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up CacheKey and CacheTTL decorators
Using CacheInterceptor which is not a decorator here
Using CacheConfig which is for global settings
5fill in blank
hard

Fill all three blanks to create a cached method with a custom key, TTL, and global cache config.

NestJS
@[1]()
@[2]('profile_cache')
@[3](1200)
fetchProfile() {
  return { name: 'Bob', age: 30 };
}
Drag options to blanks, or click blank then click option'
ACacheConfig
BCacheKey
CCacheTTL
DCacheable
Attempts:
3 left
💡 Hint
Common Mistakes
Using CacheConfig instead of Cacheable to enable caching
Mixing up the order of decorators
Using CacheInterceptor which is unrelated here