ncc = new NearCacheConfig(); ncc.setCacheLocalEntries(true); ncc.setEvictionPolicy("LRU"); ncc.setMaxSize(500000);
nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value)); } else if ("local-update-policy".equals(nodeName)) { NearCacheConfig.LocalUpdatePolicy policy = NearCacheConfig.LocalUpdatePolicy.valueOf(value);
nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value)); } else if ("local-update-policy".equals(nodeName)) { NearCacheConfig.LocalUpdatePolicy policy = NearCacheConfig.LocalUpdatePolicy.valueOf(value);
nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value)); } else if ("local-update-policy".equals(nodeName)) { nearCacheConfig.setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.valueOf(value));
nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value)); } else if ("local-update-policy".equals(nodeName)) { nearCacheConfig.setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.valueOf(value));
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.BINARY) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<Integer, Article> cache = createCacheWithNearCache(nearCacheConfig); Article article = new Article("foo"); cache.put(1, article); // the first get() will populate the Near Cache Article firstGet = cache.get(1); // the second and third get() will be served from the Near Cache Article secondGet = cache.get(1); Article thirdGet = cache.get(1); printNearCacheStats(cache); System.out.println("Since we use in-memory format BINARY, the article instances from the Near Cache will be different."); System.out.println("Compare first and second article instance: " + (firstGet == secondGet)); System.out.println("Compare second and third article instance: " + (secondGet == thirdGet)); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<Integer, Article> cache = createCacheWithNearCache(nearCacheConfig); Article article = new Article("foo"); cache.put(1, article); // the first get() will populate the Near Cache Article firstGet = cache.get(1); // the second and third get() will be served from the Near Cache Article secondGet = cache.get(1); Article thirdGet = cache.get(1); printNearCacheStats(cache); System.out.println("Since we use in-memory format BINARY, the article instances from the Near Cache will be different."); System.out.println("Compare first and second article instance: " + (firstGet == secondGet)); System.out.println("Compare second and third article instance: " + (secondGet == thirdGet)); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }
public void run() { NearCacheConfig nearCacheConfig1 = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); .setInMemoryFormat(InMemoryFormat.OBJECT) .setSerializeKeys(true) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2));
public NearCacheConfig asNearCacheConfig(SerializationService serializationService) { NearCacheConfig config = new NearCacheConfig(); config.setName(name); config.setInMemoryFormat(inMemoryFormat); config.setSerializeKeys(serializeKeys); config.setInvalidateOnChange(invalidateOnChange); config.setTimeToLiveSeconds(timeToLiveSeconds); config.setMaxIdleSeconds(maxIdleSeconds); config.setEvictionConfig(evictionConfigHolder.asEvictionConfg(serializationService)); config.setCacheLocalEntries(cacheLocalEntries); config.setLocalUpdatePolicy(LocalUpdatePolicy.valueOf(localUpdatePolicy)); config.setPreloaderConfig(preloaderConfig); return config; }
public NearCacheConfig asNearCacheConfig(SerializationService serializationService) { NearCacheConfig config = new NearCacheConfig(); config.setName(name); config.setInMemoryFormat(inMemoryFormat); config.setSerializeKeys(serializeKeys); config.setInvalidateOnChange(invalidateOnChange); config.setTimeToLiveSeconds(timeToLiveSeconds); config.setMaxIdleSeconds(maxIdleSeconds); config.setEvictionConfig(evictionConfigHolder.asEvictionConfg(serializationService)); config.setCacheLocalEntries(cacheLocalEntries); config.setLocalUpdatePolicy(LocalUpdatePolicy.valueOf(localUpdatePolicy)); config.setPreloaderConfig(preloaderConfig); return config; }
cacheMapNLConfig.setCacheLocalEntries(false); cacheMapNLConfig.setEvictionPolicy("LRU"); cacheMapNLConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setTimeToLiveSeconds(TIME_TO_LIVE_SECONDS) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<Integer, Article> cache = createCacheWithNearCache(nearCacheConfig); cache.put(1, new Article("foo")); printNearCacheStats(cache, "The put(1, article) call has no effect on the empty Near Cache"); cache.get(1); printNearCacheStats(cache, "The first get(1) call populates the Near Cache"); waitForExpirationTask(TIME_TO_LIVE_SECONDS); printNearCacheStats(cache, "We've waited for the time-to-live-seconds, so the Near Cache entry is expired."); cache.get(1); printNearCacheStats(cache, "The next get(1) call is fetching the value again from the cache"); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }
private static Config newConfig() { NearCacheConfig nearCacheConfig = new NearCacheConfig(); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); evictionConfig.setMaximumSizePolicy(USED_NATIVE_MEMORY_PERCENTAGE); evictionConfig.setSize(90); nearCacheConfig.setInMemoryFormat(NATIVE); nearCacheConfig.setInvalidateOnChange(true); nearCacheConfig.setCacheLocalEntries(true); nearCacheConfig.setName("default"); MapConfig mapConfig = new MapConfig(); mapConfig.setName("default"); mapConfig.setNearCacheConfig(nearCacheConfig); NativeMemoryConfig memoryConfig = new NativeMemoryConfig(); memoryConfig.setEnabled(true); memoryConfig.setSize(new MemorySize(128, MEGABYTES)); memoryConfig.setAllocatorType(STANDARD); Config config = new Config(); config.addMapConfig(mapConfig); config.setNativeMemoryConfig(memoryConfig); config.setLicenseKey(ENTERPRISE_LICENSE_KEY); return config; } }
serviceCacheConfig.setEvictionPolicy("NONE"); serviceCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); serviceCacheConfig.setCacheLocalEntries(true); // this enables the local caching serviceConfig.setNearCacheConfig(serviceCacheConfig); serviceEndpointCacheConfig.setEvictionPolicy("NONE"); serviceEndpointCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); serviceEndpointCacheConfig.setCacheLocalEntries(true); // this enables the local caching serviceEndpointConfig.setNearCacheConfig(serviceEndpointCacheConfig); clientCacheConfig.setEvictionPolicy("NONE"); clientCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); clientCacheConfig.setCacheLocalEntries(true); // this enables the local caching clientConfig.setNearCacheConfig(clientCacheConfig); codeCacheConfig.setMaxIdleSeconds(10 * 60 * 1000); // 10 minutes max idle seconds codeCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); codeCacheConfig.setCacheLocalEntries(true); // this enables the local caching codeConfig.setNearCacheConfig(codeCacheConfig); config.addMapConfig(codeConfig); referenceCacheConfig.setMaxIdleSeconds(10 * 60 * 1000); // 10 minutes max idle seconds referenceCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); referenceCacheConfig.setCacheLocalEntries(true); // this enables the local caching referenceConfig.setNearCacheConfig(referenceCacheConfig); config.addMapConfig(referenceConfig); providerCacheConfig.setEvictionPolicy("NONE"); providerCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setMaxIdleSeconds(MAX_IDLE_SECONDS) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<Integer, Article> cache = createCacheWithNearCache(nearCacheConfig); cache.put(1, new Article("foo")); printNearCacheStats(cache, "The put(1, article) call has no effect on the empty Near Cache"); cache.get(1); printNearCacheStats(cache, "The first get(1) call populates the Near Cache"); // with this short sleep time, the Near Cache entry should not expire for (int i = 0; i < 20; i++) { cache.get(1); sleepMillis(100); } printNearCacheStats(cache, "We have called get(1) every 100 ms, so the Near cache entry could not expire"); waitForExpirationTask(MAX_IDLE_SECONDS); printNearCacheStats(cache, "We've waited for max-idle-seconds, so the Near Cache entry is expired."); cache.get(1); printNearCacheStats(cache, "The next get(1) call is fetching the value again from the cache"); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }