protected NearCacheConfig createNearCacheConfig(String cacheName, InMemoryFormat inMemoryFormat) { return new NearCacheConfig() .setName(DEFAULT_CACHE_NAME) .setInMemoryFormat(inMemoryFormat); }
LOGGER.warning("The element <eviction-policy/> for <near-cache/> is deprecated, please use <eviction/> instead!"); } else if ("in-memory-format".equals(nodeName)) { nearCacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(value))); } else if ("serialize-keys".equals(nodeName)) { serializeKeys = Boolean.parseBoolean(value);
LOGGER.warning("The element <eviction-policy/> for <near-cache/> is deprecated, please use <eviction/> instead!"); } else if ("in-memory-format".equals(nodeName)) { nearCacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(value))); } else if ("serialize-keys".equals(nodeName)) { serializeKeys = Boolean.parseBoolean(value);
LOGGER.warning("The element <eviction-policy/> for <near-cache/> is deprecated, please use <eviction/> instead!"); } else if ("in-memory-format".equals(nodeName)) { nearCacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(value))); } else if ("serialize-keys".equals(nodeName)) { serializeKeys = Boolean.parseBoolean(value);
LOGGER.warning("The element <eviction-policy/> for <near-cache/> is deprecated, please use <eviction/> instead!"); } else if ("in-memory-format".equals(nodeName)) { nearCacheConfig.setInMemoryFormat(InMemoryFormat.valueOf(upperCaseInternal(value))); } else if ("serialize-keys".equals(nodeName)) { serializeKeys = Boolean.parseBoolean(value);
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 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 nearCacheConfig1 = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setInMemoryFormat(InMemoryFormat.OBJECT) .setSerializeKeys(true) .setCacheLocalEntries(true)
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; }
private static ClientConfig newClientConfig(String mapName) { NativeMemoryConfig memoryConfig = new NativeMemoryConfig(); memoryConfig.setEnabled(true); memoryConfig.setSize(new MemorySize(128, MEGABYTES)); memoryConfig.setAllocatorType(STANDARD); NearCacheConfig nearCacheConfig = new NearCacheConfig(); EvictionConfig evictionConfig = nearCacheConfig.getEvictionConfig(); evictionConfig.setMaximumSizePolicy(USED_NATIVE_MEMORY_PERCENTAGE); evictionConfig.setSize(90); nearCacheConfig.setInMemoryFormat(NATIVE); nearCacheConfig.setInvalidateOnChange(true); nearCacheConfig.setName(mapName); ClientConfig clientConfig = new ClientConfig(); clientConfig.setNativeMemoryConfig(memoryConfig); clientConfig.addNearCacheConfig(nearCacheConfig); clientConfig.setLicenseKey(ENTERPRISE_LICENSE_KEY); return clientConfig; } }
cacheMapNLConfig.setCacheLocalEntries(false); cacheMapNLConfig.setEvictionPolicy("LRU"); cacheMapNLConfig.setInMemoryFormat(InMemoryFormat.OBJECT); cacheMapNLConfig.setInvalidateOnChange(true); cacheMapNLConfig.setMaxIdleSeconds(10 * 60); /* 10 minute idle time */
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; } }
NearCacheConfig serviceCacheConfig = new NearCacheConfig(); serviceCacheConfig.setEvictionPolicy("NONE"); serviceCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); serviceCacheConfig.setCacheLocalEntries(true); // this enables the local caching serviceConfig.setNearCacheConfig(serviceCacheConfig); NearCacheConfig serviceEndpointCacheConfig = new NearCacheConfig(); serviceEndpointCacheConfig.setEvictionPolicy("NONE"); serviceEndpointCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); serviceEndpointCacheConfig.setCacheLocalEntries(true); // this enables the local caching serviceEndpointConfig.setNearCacheConfig(serviceEndpointCacheConfig); NearCacheConfig clientCacheConfig = new NearCacheConfig(); clientCacheConfig.setEvictionPolicy("NONE"); clientCacheConfig.setInMemoryFormat(InMemoryFormat.OBJECT); clientCacheConfig.setCacheLocalEntries(true); // this enables the local caching clientConfig.setNearCacheConfig(clientCacheConfig); codeCacheConfig.setTimeToLiveSeconds(60 * 60 * 1000); // 1 hour TTL 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); referenceCacheConfig.setTimeToLiveSeconds(60 * 60 * 1000); // 1 hour TTL 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);
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setInvalidateOnChange(false) .setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.CACHE) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<String, Article> cache1 = createCacheWithNearCache(nearCacheConfig); ICache<String, Article> cache2 = createCacheWithNearCache(nearCacheConfig); String key = generateKeyOwnedBy(getServerInstance()); cache1.put(key, new Article("foo")); printNearCacheStats(cache1, "The cache1.put(key, new Article(\"foo\")) call will populate the Near Cache of cache1, ..."); printNearCacheStats(cache2, "..., but has no effect on the Near Cache of cache2"); cache1.get(key); printNearCacheStats(cache1, "The first cache1.get(key) call be served by the Near Cache of cache1"); cache2.get(key); printNearCacheStats(cache2, "The first cache2.get(key) call populates the Near Cache of cache2"); cache1.put(key, new Article("bar")); printNearCacheStats(cache1, "The cache1.put(key, new Article(\"bar\") call will update the Near Cache of cache1, ..."); printNearCacheStats(cache2, "..., but has no effect on the Near Cache of cache2"); Article article1 = cache1.get(key); printNearCacheStats(cache1, "The second cache1.get(key) call will be served by the Near Cache of cache1"); Article article2 = cache2.get(key); printNearCacheStats(cache2, "The second cache2.get(key) call will be served by the Near Cache of cache2"); System.out.printf("The retrieved articles are not the same: %s vs. %s%n", article1.getName(), article2.getName()); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setInvalidateOnChange(true) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); ICache<String, Article> cache1 = createCacheWithNearCache(nearCacheConfig); ICache<String, Article> cache2 = createCacheWithNearCache(nearCacheConfig); String key = generateKeyOwnedBy(getServerInstance()); cache2.put(key, new Article("foo")); printNearCacheStats(cache1, "The cache2.put(key, new Article(\"foo\")) call has no effect on the Near Cache of cache1"); cache1.get(key); printNearCacheStats(cache1, "The first cache1.get(key) call populates the Near Cache of cache1"); cache2.put(key, new Article("bar")); printNearCacheStats(cache1, "The cache2.put(key, new Article(\"bar\") call will invalidate the Near Cache on cache1"); waitForInvalidationEvents(); printNearCacheStats(cache1, "The Near Cache of cache1 is empty after the invalidation event has been processed"); cache1.get(key); printNearCacheStats(cache1, "The next cache1.get(key) call populates the Near Cache again"); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }
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(); }
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInMemoryFormat(InMemoryFormat.OBJECT) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT)); ICache<Integer, Article> cache = createCacheWithNearCache(nearCacheConfig); for (int i = 1; i <= RECORD_COUNT; i++) { cache.put(i, new Article("foo" + i)); } printNearCacheStats(cache, "The put(1..100, article) calls have no effect on the empty Near Cache"); for (int i = 1; i <= RECORD_COUNT; i++) { cache.get(i); } printNearCacheStats(cache, "The first get(1..100) calls populate the Near Cache"); for (int i = 1; i <= RECORD_COUNT; i++) { cache.get(i); } printNearCacheStats(cache, "The second get(1..100) calls are served from the Near Cache"); cache.put(101, new Article("foo101")); printNearCacheStats(cache, "The put(101, article) call has no effect on the populated Near Cache"); cache.get(101); printNearCacheStats(cache, "The first get(101) call triggers the eviction and population of the Near Cache"); cache.get(101); printNearCacheStats(cache, "The second get(101) call is served from the Near Cache"); HazelcastClient.shutdownAll(); Hazelcast.shutdownAll(); }