在 hazelcast 文档中有一些对名为“default”的缓存的简短引用 - 例如,此处: http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#jcache-declarative-configuration
后面这里又提到了缓存默认配置: http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#icache-configuration
我想要的是能够配置在创建缓存时继承的“默认”设置。例如,给定以下配置片段:
<cache name="default">
<statistics-enabled>true</statistics-enabled>
<management-enabled>true</management-enabled>
<expiry-policy-factory>
<timed-expiry-policy-factory expiry-policy-type="ACCESSED" time-unit="MINUTES" duration-amount="2"/>
</expiry-policy-factory>
</cache>
我希望通过以下测试:
@Test
public void defaultCacheSettingsTest() throws Exception {
CacheManager cacheManager = underTest.get();
Cache cache = cacheManager.createCache("foo", new MutableConfiguration<>());
CompleteConfiguration cacheConfig = (CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertThat(cacheConfig.isManagementEnabled(), is(true));
assertThat(cacheConfig.isStatisticsEnabled(), is(true));
assertThat(cacheConfig.getExpiryPolicyFactory(),
is(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 2l)))
);
}
Ehcache 有一个"template"机制,我希望我能得到类似的行为。
最佳答案
Hazelcast 支持 configuration with wildcards .您可以使用 <cache name="*">
对于所有 Cache
s 共享相同的配置,或将其他模式应用到组 Cache
随心所欲的配置。
请注意,由于您已经使用 Hazelcast 声明式配置来配置您的 Cache
s,你应该使用CacheManager.getCache
而不是 createCache
获得Cache
实例:Cache
用 CacheManager.createCache(..., Configuration)
创建的忽略声明性配置,因为它们是使用 Configuration
显式配置的作为参数传递。
关于hazelcast - Hazelcast 是否支持默认缓存配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42496127/