Accessing the Caching Provider and Cache Manager
To create a Cache, you will need to access CachingProvider or CacheManager. Both are provided by Hazelcast embedded in Payara Server.
You can use injection to access and use the CachingProvider and CacheManager embedded in Payara. Inject them into your application like so:
import javax.cache.CacheManager; import javax.cache.spi.CachingProvider; import javax.inject.Inject; ... @Inject CacheManager manager; @Inject CachingProvider provider;
|Your war or jar must be an implicit or explicit bean archive, i.e. contains a CDI Bean with a bean defining annotation, an EJB Session Bean or a beans.xml file.|
Embedded Hazelcast in Payara Server has a CachingProvider and CacheManager registered to JNDI, so you do not have to create your own. To access them, import the following classes and initialize two variables like so:
import javax.cache.spi.CachingProvider; import javax.cache.CacheManager; ... Context ctx = new InitialContext(); CachingProvider provider = (CachingProvider) ctx.lookup("payara/CachingProvider"); CacheManager manager = (CacheManager) ctx.lookup("payara/CacheManager");