Hazelcast 是否支持默认缓存配置

Does Hazelcast honor a default cache configuration

在 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

我希望能够配置创建缓存时继承的 "default" 设置。例如,给定以下配置片段:

<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 有一个 "templating" 机制,我希望我能得到类似的行为。

Hazelcast 支持 configuration with wildcards。您可以对所有 Cache 使用 <cache name="*"> 以共享相同的配置,或根据需要将其他模式应用于组 Cache 配置。

请注意,由于您已经使用 Hazelcast 声明性配置来配置 Cache,因此您应该使用 CacheManager.getCache 而不是 createCache 来获取 Cache 实例:[使用 CacheManager.createCache(..., Configuration) 创建的 =11=] 忽略声明性配置,因为它们是使用作为参数传递的 Configuration 显式配置的。