@Override public void put(K key, V value, ExpiryPolicy expiryPolicy) { cache.put(key, value, expiryPolicy); }
@Override public void set(K key, V value) { cache.put(key, value); }
@Override public void put(K key, T val) { cache.put(key, val); }
@Override public void put(K k, V v) { cache.put(k, v); }
@Override public void set(K key, V value) { cache.put(key, value); }
private void putRecordsToCacheOnClient1(ICache<Integer, String> clientCache1) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(i); clientCache1.put(i, value); if (VERBOSE) { System.out.println("Put key=" + i + ", value=" + value + " to cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been put to cache through client-1"); }
private void updateRecordsInCacheOnClient1(ICache<Integer, String> clientCache1) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(i * i); clientCache1.put(i, value); if (VERBOSE) { System.out.println("Update key=" + i + ", value=" + value + " to cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been updated in cache through client-1"); }
private void putRecordsToCacheOnClient1(ICache<Integer, String> clientCache1) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(i); clientCache1.put(i, value); if (VERBOSE) { System.out.println("Put key=" + i + ", value=" + value + " to cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been put to cache through client-1"); }
private void updateRecordsInCacheOnClient1(ICache<Integer, String> clientCache1) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(RECORD_COUNT + i); clientCache1.put(i, value); if (VERBOSE) { System.out.println("Update key=" + i + ", value=" + value + " to cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been updated in cache through client-1"); }
@Override public void put(K key, T val) throws GoraException { try { cache.put(key, val); } catch (Exception e) { throw new GoraException(e); } }
private void putRecordsToCacheOnClient1(HiDensityNearCacheSupportContext<Integer, String> clientCacheContext1, HiDensityNearCacheSupportContext<Integer, String> clientCacheContext2) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(i); clientCacheContext1.cache.put(i, value); if (VERBOSE) { System.out.println("Put key=" + i + ", value=" + value + " to Hi-Density cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been put to Hi-Density cache through client-1"); System.out.println("Memory usage on client-1: " + clientCacheContext1.memoryManager.getMemoryStats()); System.out.println("Memory usage on client-2: " + clientCacheContext2.memoryManager.getMemoryStats()); }
private void updateRecordsInCacheOnClient1(HiDensityNearCacheSupportContext<Integer, String> clientCacheContext1, HiDensityNearCacheSupportContext<Integer, String> clientCacheContext2) { for (int i = 0; i < RECORD_COUNT; i++) { String value = generateValueFromKey(i * i); clientCacheContext1.cache.put(i, value); if (VERBOSE) { System.out.println("Update key=" + i + ", value=" + value + " to Hi-Density cache through client-1"); } } System.out.println(RECORD_COUNT + " records have been updated in Hi-Density cache through client-1"); System.out.println("Memory usage on client-1: " + clientCacheContext1.memoryManager.getMemoryStats()); System.out.println("Memory usage on client-2: " + clientCacheContext2.memoryManager.getMemoryStats()); }
@TimeStep public void timeStep(BaseThreadState state) { int key = state.randomInt(keyCount); if (!cache.containsKey(key)) { cache.put(key, 0, expiryPolicy); } }
@TimeStep(prob = 0.4) public void put(ThreadState state) { int key = state.randomInt(keyCount); cache.put(key, state.randomLong(), expiryPolicy); state.counter.putExpiry++; }
@TimeStep(prob = 0.8) public void put(ThreadState state) { int key = state.randomInt(); cache.put(key, value); state.counter.put++; state.assertSize(); }
@SuppressWarnings("unchecked") public static void main(String[] args) { CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); // Use eviction policy comparator by its instance CacheConfig cacheConfig1 = createCacheConfig("MyCache_1", false); ICache<Integer, String> cache1 = (ICache<Integer, String>) cacheManager.createCache("MyCache_1", cacheConfig1); // Default max-size for eviction is 10K. // With partition based cluster wide approximation, after almost 15K elements (for default 271 partition), // it is guaranteed that there will be eviction. for (int i = 0; i < 20000; i++) { cache1.put(i, "Value-" + i); } // Use eviction policy comparator by its name CacheConfig cacheConfig2 = createCacheConfig("MyCache_2", true); ICache<Integer, String> cache2 = (ICache<Integer, String>) cacheManager.createCache("MyCache_2", cacheConfig2); // Default max-size for eviction is 10K. // With partition based cluster wide approximation, after almost 15K elements (for default 271 partition), // it is guaranteed that there will be eviction. for (int i = 0; i < 20000; i++) { cache2.put(i, "Value-" + i); } cachingProvider.close(); }
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 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) .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(); }