Caching libraries such as Ehcache, Hazelcast, Infinispan, GridGain, Apache Ignite in the Java ecosystem are common and indeed is needed in many different kinds of solutions to optimize the application in various ways.
The simplest libraries are just in-memory object maps with simple evict rules, while the most advanced caching libraries have efficient cross-JVM features and configurable options to write the cache state to disk, and a good basis for memory heavy computation.
What is JCache?
- JCache is JSR 107 specification.
- JCache is the Java standard API for caching on the Java platform.
- JCache provides an API for applications to be able to create and work with in-memory cache of objects.
- JCache provides a very simple to use, but yet very powerful API for data access.
- JCache allows vendors enough freedom in their own implementations.
Benefits of JCache
- In-Memory Key Value Store
- Basic Cache Operations
- ConcurrentMap APIs
- Collocated Processing (EntryProcessor)
- Events and Metrics
- Pluggable Persistence
Components of JCache
The specification itself defines high level components (interfaces) and some of them are listed below:
- Caching Provider – used to control Caching Managers and can deal with several of them
- Cache Manager – deals with create, read, destroy operations on a Cache
- Cache – stores entries (the actual data) and exposes CRUD interfaces to deal with the entries
- Entry – abstraction on top of a key-value pair akin to a java.util.Map
Implementation of JCache
JCache defines a set of interfaces, which are implemented by different vendors a.k.a providers as given below:
- Terracotta – Ehcache
- Oracle – Coherence
- JBoss – Infinispan
- IBM – ExtemeScale
- SpringSource – Gemfire
- Google App Engine Java
- Reference Implementation – this is more for reference purpose rather than a production quality implementation.
You can read an example on JCache implementation using EhCache Spring JCache support.
Thanks for reading.