8.2. Create a local cache
Creating a local cache, using default configuration options as defined by the JCache API specification, is as simple as doing the following:
Warning
By default, the JCache API specifies that data should be stored as
storeByValue
, so that object state mutations outside of operations to the cache, won’t have an impact in the objects stored in the cache. JBoss Data Grid has so far implemented this using serialization/marshalling to make copies to store in the cache, and that way adhere to the spec. Hence, if using default JCache configuration with Infinispan, data stored must be marshallable.
Alternatively, JCache can be configured to store data by reference. To do that simply call:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Cache<String, String> cache = cacheManager.createCache("namedCache", new MutableConfiguration<String, String>().setStoreByValue(false));
Cache<String, String> cache = cacheManager.createCache("namedCache",
new MutableConfiguration<String, String>().setStoreByValue(false));
Library Mode Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
With Library mode a
CacheManager
may be configured by specifying the location of a configuration file via the URL
parameter of CachingProvider.getCacheManager
. This allows the opportunity to define clustered caches, which a reference can be later obtained to using the CacheManager.getCache
method; otherwise local caches can only be used, created from the CacheManager.createCache
.
Client-Server Mode Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
With Client-Server mode specific configurations of a remote
CacheManager
is performed by passing standard HotRod client properties via properties
parameter of CachingProvider.getCacheManager
. The remote servers referenced must be running and able to receive the request.
If not specified the default address and port will be used (127.0.0.1:11222). In addition, contrary to Library mode, the first time a cache reference is obtained
CacheManager.createCache
must be used so that the cache may be registered internally. Subsequent queries may be performed via CacheManager.getCache
.