Cache key

Now, we are able to control our cache and activate our cache operations on our methods; what did we miss?—A way to control the key used for the cache. For instance, let's take the following method:

@CacheResultpublic Quote findQuote(String symbol)

Here, the natural key is the symbol, so it would be nice if JCache could do it automatically, right? It is the cache, but the rule is a bit more complicated because if you apply the same reasoning for a create method, then it doesn't work:

@CacheResultpublic Quote create(String symbol, double price)

Here, we want the result to be cached, but if findQuote() must match the create() method, then we must have a way to ask JCache to use only symbol in the key.

To do so, JCache relies on the ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.