Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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
✗ Incorrect
The @Cacheable() decorator marks the method to use caching.
2fill in blank
mediumComplete 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'
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
✗ Incorrect
The @CacheKey('custom_key') decorator sets a custom key for caching.
3fill in blank
hardFix 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'
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
✗ Incorrect
The @CacheTTL(3000) decorator sets the cache expiration time in seconds.
4fill in blank
hardFill 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'
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
✗ Incorrect
@CacheKey('session_data') sets the cache key, and @CacheTTL(600) sets the cache duration.
5fill in blank
hardFill 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'
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
✗ Incorrect
@Cacheable() enables caching, @CacheKey('profile_cache') sets the key, and @CacheTTL(1200) sets the cache duration.