我目前正在尝试将 HazelCast 缓存与 jcache 对象集成,以基于其标准进行开发。
我需要集成大量不同的配置,为此我创建了一个 hazelcast.xml。在我尝试使用 hazelcast 地图对象(com.hazelcast.core.IMap)的地方,我得到了它的工作,因此我可以使用适当的配置获取缓存:
private static void initHazelcast() {
log.info("initHazelcast()");
Config cfg = null;
try {
cfg = new XmlConfigBuilder("./src/main/resources/hazelcast.xml").build();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
IMap map = hazelcastInstance.getMap("EXPIR00001");
log.info("initHazelcast() End");
}
HazelCast.xml:
<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.9.xsd"
xmlns="http://www.hazelcast.com/schema/config">
<map name="EXPIR00001">
<time-to-live-seconds>1</time-to-live-seconds>
<max-idle-seconds>1</max-idle-seconds>
<eviction-policy>LRU</eviction-policy>
<max-size policy="PER_NODE">5000</max-size>
</map>
</hazelcast>
现在我尝试使用 JCache 的 javax.cache.Cache 类。
我正在使用这个例子,但我没有像这样检索 xml 配置:
http://docs.hazelcast.org/docs/3.9.3/manual/html-single/index.html#jcache-declarative-configuration 和 http://docs.hazelcast.org/docs/3.9.3/manual/ html-single/index.html#scoping-to-join-clusters
Hazelcast.xml:
<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.9.xsd"
xmlns="http://www.hazelcast.com/schema/config">
<cache name="EXPIR00001">
<backup-count>1</backup-count>
<async-backup-count>1</async-backup-count>
<in-memory-format>BINARY</in-memory-format>
<eviction size="10000" max-size-policy="ENTRY_COUNT" eviction-policy="LRU" />
<expiry-policy-factory>
<timed-expiry-policy-factory expiry-policy-type="CREATED"
duration-amount="1"
time-unit="DAYS"/>
</expiry-policy-factory>
</cache>
</hazelcast>
方法java:
private static void initHazelcast() {
log.info("initHazelcast()");
Config cfg = null;
try {
cfg = new XmlConfigBuilder("./src/main/resources/hazelcast.xml").build();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
hazelcastInstance = Hazelcast.newHazelcastInstance(cfg);
CacheManager manager = Caching.getCachingProvider().getCacheManager();
//In JCache
Cache<byte[], byte[]> cache = manager.getCache( "EXPIR00001" );
log.info("initHazelcast() End");
}
CacheManager 管理器你怎么能与 hazelcast 实例联系起来??管理器对象不检索缓存 Id = "EXPIR00001"
我需要从一个 xml 文件进行配置,decalratively (Hazelcast.xml)。有很多配置,我们可能需要。
我不能使用:http: //docs.hazelcast.org/docs/3.9.3/manual/html-single/index.html#hazelcast-jcache