Programmatic API

A JCache cache can be very quickly accessed using the Caching factory:

Cache<String, Quote> quotes = Caching.getCache("packt.quotes", String.class, Quote.class);quotes.put(symbol, quote);

The getCache method directly gives you back a Cache instance, which allows you to write/read data. The API is then close to a plain Map semantic. However, this only works if the cache already exists; otherwise, the getCache call will fail.

To understand how JCache works, we need to look at how the instances are managed. This design is pretty common in Java EE and is quite efficient in general:

  • A factory method gives you a provider instance (a link between the API and implementation)
  • The provider gives you a manager, which stores instances ...

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.