CDI integration

The JCache specification (and, therefore, complete implementations) comes with a CDI integration. The idea is to enable you to cache your data without having to deal with all the glue of Cache.

The CDI integration provides four operations usable with CDI:

  • @CacheResult: This is probably the most useful feature that will cache a method result and serve it from the cache for later invocations.
  • @CacheRemove: This removes data from the cache.
  • @CacheRemoveAll: This removes all the data of the referenced cache.
  • @CachePut: This adds data to the cache. It relies on @CacheValue, which marks a parameter to identify the value to cache.

If we want to cache our quotes in our service, we can just decorate our finder method with @CacheResult ...

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.