@Override protected NearCacheConfig createNearCacheConfig(String cacheName, InMemoryFormat inMemoryFormat) { NearCacheConfig nearCacheConfig = super.createNearCacheConfig(cacheName, inMemoryFormat); if (inMemoryFormat == InMemoryFormat.NATIVE) { EvictionConfig evictionConfig = new EvictionConfig() .setMaximumSizePolicy(MaxSizePolicy.USED_NATIVE_MEMORY_PERCENTAGE) .setSize(99); nearCacheConfig.setEvictionConfig(evictionConfig); } return nearCacheConfig; }
/** * This method creates a copy of {@link NearCacheConfig} <strong>without</strong> copying read-only objects for * class fields, which may contain trash from previous invocations of near cache methods (this problem comes from * the fact, that HZ treats map configs as a const values after cluster startup, but atlassian cache allows to * change them after cluster is stared) * * @param nearCacheConfig {@link NearCacheConfig} to be copied * @return copy of the {@link NearCacheConfig} without read-only objects */ private NearCacheConfig copyNearCacheConfig(@Nonnull NearCacheConfig nearCacheConfig) { NearCacheConfig nearCacheConfigCopy = new NearCacheConfig(nearCacheConfig); EvictionConfig evictionConfigCopy = new EvictionConfig(nearCacheConfig.getEvictionConfig()); nearCacheConfigCopy.setEvictionConfig(evictionConfigCopy); NearCachePreloaderConfig preloaderConfigCopy = new NearCachePreloaderConfig(nearCacheConfigCopy.getPreloaderConfig()); nearCacheConfigCopy.setPreloaderConfig(preloaderConfigCopy); return nearCacheConfigCopy; }
nearCacheConfig.setLocalUpdatePolicy(policy); } else if ("eviction".equals(nodeName)) { nearCacheConfig.setEvictionConfig(getEvictionConfig(child, true));
nearCacheConfig.setLocalUpdatePolicy(policy); } else if ("eviction".equals(nodeName)) { nearCacheConfig.setEvictionConfig(getEvictionConfig(child, true));
nearCacheConfig.setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.valueOf(value)); } else if ("eviction".equals(nodeName)) { nearCacheConfig.setEvictionConfig(getEvictionConfig(child)); } else if ("preloader".equals(nodeName)) { nearCacheConfig.setPreloaderConfig(getNearCachePreloaderConfig(child));
nearCacheConfig.setLocalUpdatePolicy(NearCacheConfig.LocalUpdatePolicy.valueOf(value)); } else if ("eviction".equals(nodeName)) { nearCacheConfig.setEvictionConfig(getEvictionConfig(child)); } else if ("preloader".equals(nodeName)) { nearCacheConfig.setPreloaderConfig(getNearCachePreloaderConfig(child));
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(); }
.setCacheLocalEntries(true) .setInvalidateOnChange(false) .setEvictionConfig(createEvictionConfigWithEntryCountPolicy(RECORD_COUNT * 2)); .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; }
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(); }
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(); }