-
1. Re: Custom read-though loader is now working using the JCache get
william.burns Aug 13, 2015 12:57 PM (in response to liuxiaodu)JCache Configuration by default disables read through. You need to explicitly enable this through the configuration.
// Retrieve the system wide cache manager CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(); // Define a named cache with default JCache configuration Cache<String, String> cache = cacheManager.createCache("namedCache", new MutableConfiguration<String, String>().setReadThrough(true));
-
2. Re: Custom read-though loader is now working using the JCache get
liuxiaodu Aug 13, 2015 1:46 PM (in response to william.burns)Thanks for your help.
Regarding the configuration, we prefer the using configuration file. For example, here is one of our configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:7.0 http://www.infinispan.org/schemas/infinispan-config-7.0.xsd"
xmlns="urn:infinispan:config:7.0">
<jgroups>
<stack-file name="tcp" path="${catalina.base}/conf/tcp-nio.xml" />
</jgroups>
<cache-container default-cache="default">
<transport cluster="jcache-cluster" stack="tcp" node-name="${nodeName}" />
<replicated-cache name="repl" mode="SYNC" >
<persistence passivation="false">
<file-store
shared="false"
preload="true"
fetch-state="true"
read-only="false"
purge="false"
path="${catalina.base}/temp/infinispan">
<write-behind flush-lock-timeout="15000" thread-pool-size="5" />
</file-store>
<store class="org.jboss.infinispan.jcache.ReplCustomLoader"
shared="false"
preload="false"
fetch-state="false"
read-only="true"
purge="false"
singleton="false"
/>
</persistence>
<transaction mode="BATCH" />
</replicated-cache>
</cache-container>
</infinispan>
We use the following method to configure and retrieve the JCache instance:
javax.cache.CacheManager jCacheManager = Caching.getCachingProvider().getCacheManager(configurationFile.toURI(), Thread.currentThread().getContextClassLoader());
javax.cache.Cache<String, String> cache = this.jCacheManager.getCache(cacheName);
We would like to know if it is possible to set this isReadThrough in the above configuration file instead of in the code. We prefer using configuration since we can share the same cache manager and change the configuration to allow server configuration do have loader configured and client do not have the loader configured.
Thanks again.
-
3. Re: Custom read-though loader is now working using the JCache get
galder.zamarreno Aug 14, 2015 10:11 AM (in response to liuxiaodu)Hi Louie, there might a way to do what you suggest. Essentially, you'd need to create caches via "createCache(String cacheName, C configuration)", and in the configuration, pass your own subclass of javax.cache.configuration.CompleteConfiguration. This subclass would be created with Infinispan XML configuration as parsed (e.g. created the cache manager and get a cache's configuration would do), and then in isReadThrough implementation, you could check for example if the Infinispan XML configuration has a persistence store, and if so enable isReadThrough. You could also do this if you subclass MutableConfiguration, but there's a problem with MutableConfiguration which is the fact that you don't know when isReadThrough is false, whether that's because it's default value or because someone called setReadThrough specifically. If you provide your own implementation javax.cache.configuration.CompleteConfiguration, you can initialise isReadThrough instance variable as null, and null serves you as a way to know that the user has not explicitly called setReadThrough.
-
4. Re: Custom read-though loader is now working using the JCache get
liuxiaodu Aug 14, 2015 5:14 PM (in response to galder.zamarreno)Than you all for the help. I found the solution by cast the configuration to MutableConfiguration and set the flag. Here is the steps:
javax.cache.CacheManager jCacheManager = Caching.getCachingProvider().getCacheManager(configurationFile.toURI(), Thread.currentThread().getContextClassLoader());
javax.cache.Cache<String, String> cache = this.jCacheManager.getCache(cacheName);
final MutableConfiguration<String, String> cfg = cache.getConfiguration(MutableConfiguration.class);\
cache.get(key); //read-through works know.
Louie