Performance: Cache key strategies
MEDIUM IMPACT
Cache key strategies affect how efficiently cached data is retrieved, impacting response time and server load.
@Cacheable(cacheNames = "users", key = "#user.id") public User getUser(User user) { ... }
@Cacheable(cacheNames = "users", key = "#user.toString()") public User getUser(User user) { ... }
| Pattern | Cache Key Complexity | Cache Hits | Backend Calls | Verdict |
|---|---|---|---|---|
| Complex object toString() as key | High | Low | High | [X] Bad |
| Simple unique ID as key | Low | High | Low | [OK] Good |
| Including mutable fields in key | High | Low | High | [X] Bad |
| Explicit concatenated keys | Low | High | Low | [OK] Good |