ncc.setEvictionPolicy("LRU"); ncc.setMaxSize(500000); ncc.setInvalidateOnChange(true); Map<String, NearCacheConfig> nearCache = new HashMap<String, NearCacheConfig>(); nearCache.put("CitiesLocal", ncc);
nearCacheConfig.setSerializeKeys(serializeKeys); } else if ("invalidate-on-change".equals(nodeName)) { nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value));
nearCacheConfig.setSerializeKeys(serializeKeys); } else if ("invalidate-on-change".equals(nodeName)) { nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value));
nearCacheConfig.setSerializeKeys(serializeKeys); } else if ("invalidate-on-change".equals(nodeName)) { nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(Boolean.parseBoolean(value));
nearCacheConfig.setSerializeKeys(serializeKeys); } else if ("invalidate-on-change".equals(nodeName)) { nearCacheConfig.setInvalidateOnChange(Boolean.parseBoolean(value)); } else if ("cache-local-entries".equals(nodeName)) { nearCacheConfig.setCacheLocalEntries(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(); }
.setInMemoryFormat(InMemoryFormat.OBJECT) .setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); .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 void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig(); nearCacheConfig.setInvalidateOnChange(true); ICache<Integer, String> clientCache1 = createCacheWithNearCache(nearCacheConfig); ICache<Integer, String> clientCache2 = getCacheWithNearCache(); // put records to remote cache through client-1 putRecordsToCacheOnClient1(clientCache1); // get records from remote cache through client-2 getRecordsFromCacheOnClient2(clientCache2); // get records from Near Cache on client-2 getRecordsFromNearCacheOnClient2(clientCache2); // update records in remote cache through client-1 updateRecordsInCacheOnClient1(clientCache1); // wait a little for invalidation events waitForInvalidationEvents(); // get invalidated records from remote cache on client-2 getInvalidatedRecordsFromNearCacheOnClient2(clientCache2); shutdown(); }
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 void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInvalidateOnChange(true); HiDensityNearCacheSupportContext<Integer, String> clientCacheContext1 = createHiDensityCacheWithHiDensityNearCache(nearCacheConfig); HiDensityNearCacheSupportContext<Integer, String> clientCacheContext2 = createHiDensityCacheWithHiDensityNearCache(nearCacheConfig); // put records to cache through client-1 putRecordsToCacheOnClient1(clientCacheContext1, clientCacheContext2); // get records from cache through client-2 getRecordsFromCacheOnClient2(clientCacheContext1, clientCacheContext2); // get records from Near Cache on client-2 getRecordsFromNearCacheOnClient2(clientCacheContext1, clientCacheContext2); // update records at cache through client-1 updateRecordsInCacheOnClient1(clientCacheContext1, clientCacheContext2); // wait a little for invalidation events sleepSeconds(5); // get invalidated records from Near Cache on client-2 getInvalidatedRecordsFromNearCacheOnClient2(clientCacheContext1, clientCacheContext2); shutdown(); }
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; } }
public void run() { NearCacheConfig nearCacheConfig = createNearCacheConfig() .setInvalidateOnChange(true); CacheConfig<Integer, String> cacheConfig = createCacheConfig(); cacheConfig.setDisablePerEntryInvalidationEvents(true); ICache<Integer, String> clientCache1 = createCacheWithNearCache(cacheConfig, nearCacheConfig); ICache<Integer, String> clientCache2 = getCacheWithNearCache(nearCacheConfig); // put records to remote cache through client-1 putRecordsToCacheOnClient1(clientCache1); // get records from remote cache through client-2 getRecordsFromCacheOnClient2(clientCache2); // get records from Near Cache on client-2 getRecordsFromNearCacheOnClient2(clientCache2); // update records in remote cache through client-1 updateRecordsInCacheOnClient1(clientCache1); // wait a little for invalidation events to be sent in batch sleepSeconds(2 * INVALIDATION_EVENT_FLUSH_FREQ_SECONDS); // get old records from Near Cache on client-2 (because we have disabled per entry invalidation event) getStillOldRecordsFromNearCacheOnClient2(clientCache2); // clear cache through client-1 clientCache1.clear(); // wait a little for invalidation events to be sent in batch sleepSeconds(2 * INVALIDATION_EVENT_FLUSH_FREQ_SECONDS); // try to get records from Near Cache and can't find any, since they are invalidated from Near Cache on client-2 // due to clear() on client-1, because it's a full-flush operation and triggers invalidation even though // per entry invalidation event is disabled cantFindAnyRecordFromNearCacheOnClient2(clientCache2); shutdown(); }
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; } }
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) .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(); }
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(); }