Use JCache providers to create caches for a specification compliant implementation. Those providers abstract the platform specific behavior and bindings and provide the different JCache required features.
Hazelcast has two types of providers. Depending on your application setup and the cluster topology, you can use the Client Provider (used by Hazelcast clients) or the Member Provider (used by cluster members).
For more information about cluster topologies and Hazelcast clients, see the Hazelcast Topology section.
Hazelcast provides three
A member-side implementation: the
CacheManagers created by this provider are backed by member-side
A client-side implementation: the
CacheManagers created by this provider are backed by client-side
A delegating caching provider that can be configured to delegate to the member- or client-side implementation.
When Hazelcast is the only JCache provider on the classpath, the default
caching provider returned by
// provides the default delegating caching provider CachingProvider provider = javax.cache.Caching.getCachingProvider();
By default, the delegating caching provider chooses the client-side implementation,
however it can be configured to explicitly pick the client- or member-side implementation.
This is achieved by setting the
hazelcast.jcache.provider.type system property to
member. The legacy value
server is also accepted as an alias for
member, however its
usage is discouraged as it will be removed in a future version.
System.setProperty("hazelcast.jcache.provider.type", "member"); // the returned provider will delegate to the member-side caching provider CachingProvider provider = javax.cache.Caching.getCachingProvider();
You can also configure the default
CachingProvider by setting its fully qualified
class name to the value of the
javax.cache.spi.CachingProvider system property.
The system property can be defined at the
java command line (using
The JCache API also provides methods to explicitly request the instantiation of
CachingProvider by supplying its fully qualified class name. This is
useful to explicitly choose Hazelcast as
CachingProvider in case multiple
implementations reside on the classpath.
// provides the member-side caching provider CachingProvider provider = Caching.getCachingProvider("com.hazelcast.cache.HazelcastMemberCachingProvider");
Since Hazelcast 4.0.3 the fully qualified class names for Hazelcast’s
CachingProvider implementations are:
CachingProvider(picks member- or client-side provider depending on configuration):
com.hazelcast.cache.HazelcastMemberCachingProvider. The legacy class name
com.hazelcast.cache.impl.HazelcastServerCachingProvideris also accepted, however its usage is discouraged and will be removed in a future version.
com.hazelcast.client.cache.HazelcastClientCachingProvider. The legacy class name
com.hazelcast.client.cache.impl.HazelcastClientCachingProvideris also accepted, however its usage is discouraged and will be removed in a future version.