Card 06/ 07

ExerciseDifficulty: Advanced1 min

Which Annotation?

A RideHistoryService has a method getHistory(riderId) that's expensive and rarely changes, and a method clearHistory(riderId) that deletes a rider's history entirely. Which caching annotation belongs on each?

See the answer

@Cacheable on getHistory — skip the expensive work when a cached answer already exists. @CacheEvict on clearHistory — there's nothing to put back after a delete, only something to remove.