2017-02-27 53 views
2

在hazelcast文檔之外,還有一個名爲「默認」的緩存一些簡短的引用 - 例如,在這裏: http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#jcache-declarative-configuration是否Hazelcast榮譽器的默認緩存配置

後來,有緩存的默認配置的另一提到這裏: 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有一個「模板」機制,我希望我能得到一個類似的行爲。

回答

2

Hazelcast支持configuration with wildcards。您可以使用<cache name="*">爲所有Cache s共享相同的配置,或者根據需要將其他模式應用於Cache配置。

注意,因爲你已經在使用Hazelcast聲明配置來配置你的Cache S,你應該使用的CacheManager.getCache代替createCache獲得Cache實例:用CacheManager.createCache(..., Configuration)無視的聲明配置創建Cache小號,因爲它們與Configuration通過明確配置作爲論據。

相關問題