當前位置: 首頁>>代碼示例>>Java>>正文


Java NearCacheConfig.setTimeToLiveSeconds方法代碼示例

本文整理匯總了Java中com.hazelcast.config.NearCacheConfig.setTimeToLiveSeconds方法的典型用法代碼示例。如果您正苦於以下問題:Java NearCacheConfig.setTimeToLiveSeconds方法的具體用法?Java NearCacheConfig.setTimeToLiveSeconds怎麽用?Java NearCacheConfig.setTimeToLiveSeconds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hazelcast.config.NearCacheConfig的用法示例。


在下文中一共展示了NearCacheConfig.setTimeToLiveSeconds方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testReadFromCache

import com.hazelcast.config.NearCacheConfig; //導入方法依賴的package包/類
@Test
public void testReadFromCache() {
    System.setProperty("hazelcast.client.near.cache.enabled", "true");
    Config config = new Config();
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setMaxSize(1000);
    nearCacheConfig.setMaxIdleSeconds(10);
    nearCacheConfig.setTimeToLiveSeconds(20);
    config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
    String mapName = "testReadFromCache";
    IMap<String, String> mapH = h.getMap(mapName);
    mapH.put("a", "a");
    HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
    Map<Object, Object> mapC = client.getMap(mapName);

    assertEquals("a", mapC.get("a"));
    int hit = mapH.getMapEntry("a").getHits();
    mapC.get("a");
    assertEquals(mapH.getMapEntry("a").getHits(), hit);
    for (int i = 0; i < 100; i++) {
        mapC.get("a");
    }
    assertEquals(mapH.getMapEntry("a").getHits(), hit);
}
 
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:26,代碼來源:ClientMapGuavaCacheTest.java

示例2: testNoNearCacheConfig

import com.hazelcast.config.NearCacheConfig; //導入方法依賴的package包/類
@Test
public void testNoNearCacheConfig() {
    System.setProperty("hazelcast.client.near.cache.enabled", "false");
    Config config = new Config();
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setMaxSize(1000);
    nearCacheConfig.setMaxIdleSeconds(10);
    nearCacheConfig.setTimeToLiveSeconds(20);
    config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
    HazelcastInstance h = Hazelcast.newHazelcastInstance(config);
    String mapName = "testReadFromCache";
    IMap<String, String> mapH = h.getMap(mapName);
    mapH.put("a", "a");
    HazelcastClient client = HazelcastClient.newHazelcastClient(new ClientConfig());
    Map<Object, Object> mapC = client.getMap(mapName);

    assertEquals("a", mapC.get("a"));
    int hit = mapH.getMapEntry("a").getHits();
    mapC.get("a");
    assertEquals(mapH.getMapEntry("a").getHits(), ++hit);
    for (int i = 0; i < 100; i++) {
        mapC.get("a");
    }
    assertEquals(mapH.getMapEntry("a").getHits(), hit + 100);
}
 
開發者ID:health-and-care-developer-network,項目名稱:health-and-care-developer-network,代碼行數:26,代碼來源:ClientMapGuavaCacheTest.java

示例3: setupConfig

import com.hazelcast.config.NearCacheConfig; //導入方法依賴的package包/類
public static void setupConfig(HazelcastConnection hazelcastConnection) {
    MapConfig mapConfig = hazelcastConnection.getHazelcastConfig().getMapConfig(NAME_PREFIX + "*");
    mapConfig.setInMemoryFormat(InMemoryFormat.BINARY);
    mapConfig.setTimeToLiveSeconds(10);
    mapConfig.setMaxIdleSeconds(10);
    mapConfig.setBackupCount(0);
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setTimeToLiveSeconds(10);
    nearCacheConfig.setInvalidateOnChange(true);
    nearCacheConfig.setMaxIdleSeconds(10);
    mapConfig.setNearCacheConfig(nearCacheConfig);
}
 
開發者ID:Flipkart,項目名稱:foxtrot,代碼行數:13,代碼來源:DistributedCache.java


注:本文中的com.hazelcast.config.NearCacheConfig.setTimeToLiveSeconds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。