0
0
NestJSframework~10 mins

Cache stores (memory, Redis) 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 import the CacheModule in a NestJS module.

NestJS
import { CacheModule } from '@nestjs/cache-manager';

@Module({
  imports: [CacheModule.[1]()],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
Asetup
Bconfigure
Cregister
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'configure' or 'init' instead of 'register' causes errors.
Forgetting to import CacheModule before using it.
2fill in blank
medium

Complete the code to set up Redis as the cache store in NestJS.

NestJS
CacheModule.register({
  store: [1],
  host: 'localhost',
  port: 6379,
}),
Drag options to blanks, or click blank then click option'
A'memory-store'
B'redis'
CmemoryStore
DredisStore
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'redis' instead of the imported redisStore function.
Confusing memory store with Redis store.
3fill in blank
hard

Fix the error in the code to inject Cache correctly in a NestJS service.

NestJS
constructor(private readonly cache: [1]) {}
Drag options to blanks, or click blank then click option'
ACache
BCacheManager
DCacheService
Attempts:
3 left
💡 Hint
Common Mistakes
Using CacheManager or CacheService instead of Cache causes injection errors.
Not marking the constructor parameter as private readonly.
4fill in blank
hard

Fill both blanks to create a cache key with a prefix and set a TTL of 5 minutes.

NestJS
await this.cache.[1]('user:123', userData, { ttl: [2] });
Drag options to blanks, or click blank then click option'
Aset
Bget
C300
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' to store data.
Setting TTL to 60 seconds instead of 300.
5fill in blank
hard

Fill all three blanks to configure CacheModule with Redis store, host, and port.

NestJS
CacheModule.register({
  store: [1],
  host: [2],
  port: [3],
}),
Drag options to blanks, or click blank then click option'
AredisStore
B'localhost'
C6379
D'memory-store'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'memory-store' instead of redisStore.
Using port as a string instead of number.
Forgetting quotes around 'localhost'.