Performance: Cache stores (memory, Redis)
This affects how fast data can be retrieved and reduces server processing time, improving response speed and user experience.
async getUser(id: string) { const cached = await this.cacheManager.get(id); if (cached) return cached; const user = await this.userService.findById(id); await this.cacheManager.set(id, user, { ttl: 300 }); return user; }
async getUser(id: string) { return await this.userService.findById(id); // Always fetches from DB }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cache (DB fetch every time) | N/A | N/A | High server delay causes slow paint | [X] Bad |
| In-memory cache store | N/A | N/A | Fast response reduces paint delay | [OK] Good |
| Redis cache store | N/A | N/A | Fast network cache reduces paint delay | [OK] Good |
await cacheManager.set('key1', 'value1', { ttl: 5 });
const val1 = await cacheManager.get('key1');
await new Promise(r => setTimeout(r, 6000));
const val2 = await cacheManager.get('key1');
What will be the values of val1 and val2 respectively?CacheModule.register({
store: 'redis',
host: 'localhost',
port: '6379'
})
But your app throws a connection error. What is the likely cause?Pass the test and this pattern moves unknown