Complete the code to set a TTL of 60 seconds in the cache manager options.
CacheModule.register({ ttl: [1] })The ttl option sets the time-to-live in seconds. Here, 60 means cache entries expire after 60 seconds.
Complete the code to inject the cache manager service in a NestJS service constructor.
constructor(@Inject(CACHE_MANAGER) private [1]: Cache) {}The injected variable name is commonly cacheManager to represent the cache service instance.
Fix the error in setting a TTL for a specific cache key using the cache manager's set method.
await this.cacheManager.set('user_123', userData, [1]);
The set method expects the TTL option as an object with a ttl property in seconds. Here, { ttl: 60 } sets TTL to 60 seconds.
Fill both blanks to configure the cache module with a TTL of 120 seconds and a max cache size of 100 items.
CacheModule.register({ ttl: [1], max: [2] })The ttl is set to 120 seconds for cache expiration, and max limits the cache size to 100 items.
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.
const key = `session:[1]`; await this.cacheManager.set(key, [2], { ttl: [3] });
The key uses a prefix session: plus the userId. The value stored is sessionData with a TTL of 30 seconds.