Card 03/ 07
All 7 cards
ExampleDifficulty: Intermediate1 min
The Cache Key Is the Arguments
lookupFare("downtown") is cached. Calling lookupFare("suburb") right after doesn't return the cached downtown fare — it runs the method again, for a different key.
different arg (suburb) after downtown cached, method ran: 1 time(s) for the new keyBy default, @Cacheable's key is generated from the method's own arguments — here, just the String zone. Two different arguments are two different keys, and two different keys are two entries that never share a cached result, however similar the underlying work is. @CachePut's explicit key = "#zone" on the previous card's updateFare is the same mechanism, spelled out by hand rather than generated automatically — needed there because updateFare takes a second argument, newFare, that must not become part of the key.