Performance: @CachePut for updating cache
MEDIUM IMPACT
This affects server response time and memory usage by controlling how cache updates happen during method execution.
@CachePut(value = "items", key = "#item.id") public Item updateItem(Item item) { // update logic return item; }
@Cacheable("items") public Item updateItem(Item item) { // update logic return item; }
| Pattern | Method Execution | Cache Update | Data Freshness | Verdict |
|---|---|---|---|---|
| @Cacheable only | Skipped if cached | No update | Stale data possible | [X] Bad |
| @CachePut | Always runs | Updates cache after | Fresh data guaranteed | [OK] Good |