Stage 1: Problem
Problem
You are building a user profile service for an e-commerce platform. The UserRepository fetches user data from MySQL. Every page load hits the database — the user dashboard, the order page, the admin panel. Response times are climbing.
Your team decides to add Redis caching. The rules:
- Cache user profiles for 5 minutes after first fetch.
- Invalidate cache when a user updates their profile.
- Log every cache hit and miss for observability.
- The rest of the codebase must not change — dozens of services call
UserRepository.findById().
Before continuing, think: How would you add caching without modifying the existing repository or its callers?