NestJS · Senior · Question 50 of 75
How would you implement response caching that varies by user in Nest?
- 1Use the default
CacheInterceptor, which is already per user - 2Cache in the DTO
- ✓Correct answer: Extend
CacheInterceptorand overridetrackBy()to include the user ID (or skip caching for authenticated requests)
Explanation
The default key is based on the URL. Caching personalized responses under a shared key leaks data.