0
0
NestJSframework~10 mins

TTL configuration 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 set a TTL of 60 seconds in the cache manager options.

NestJS
CacheModule.register({ ttl: [1] })
Drag options to blanks, or click blank then click option'
A-1
B60
C0
D6000
Attempts:
3 left
💡 Hint
Common Mistakes
Using milliseconds instead of seconds.
Setting TTL to 0 which disables expiration.
2fill in blank
medium

Complete the code to inject the cache manager service in a NestJS service constructor.

NestJS
constructor(@Inject(CACHE_MANAGER) private [1]: Cache) {}
Drag options to blanks, or click blank then click option'
AcacheClient
BcacheService
Ccache
DcacheManager
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not match the injected token.
Forgetting to mark the variable as private.
3fill in blank
hard

Fix the error in setting a TTL for a specific cache key using the cache manager's set method.

NestJS
await this.cacheManager.set('user_123', userData, [1]);
Drag options to blanks, or click blank then click option'
A{ ttl: 60 }
B60000
C60
D{ ttl: 60000 }
Attempts:
3 left
💡 Hint
Common Mistakes
Passing TTL as a raw number instead of an options object.
Confusing seconds and milliseconds units.
4fill in blank
hard

Fill both blanks to configure the cache module with a TTL of 120 seconds and a max cache size of 100 items.

NestJS
CacheModule.register({ ttl: [1], max: [2] })
Drag options to blanks, or click blank then click option'
A120
B60
C100
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up TTL and max values.
Using TTL in milliseconds instead of seconds.
5fill in blank
hard

Fill all three blanks to create a cache key with a prefix, set a TTL of 30 seconds, and store the value using the cache manager.

NestJS
const key = `session:[1]`;
await this.cacheManager.set(key, [2], { ttl: [3] });
Drag options to blanks, or click blank then click option'
AuserId
BsessionData
C30
DuserToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable for the key or value.
Setting TTL as a string instead of a number.