@Override public V get(K k) { return cache.get(k); }
@Override public V get(K key) { return cache.get(key); }
@Override public V get(K key) { return cache.get(key); }
@Override public V get(K key, ExpiryPolicy expiryPolicy) { return cache.get(key, expiryPolicy); }
@Override public T get(K key) { return cache.get(key); }
private void cantFindAnyRecordFromNearCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { String value = clientCache2.get(i); assert value == null : "Taken value from Near Cache must not be there but it is " + value + ". Because it must be invalidated due to clear on cache!"; if (VERBOSE && value != null) { System.out.println("Get key=" + i + ", value=" + value + " from Near Cache through client-2 after clear()"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from Near Cache after clear() finished in " + elapsed + " milliseconds"); }
@Override public T get(K key, String[] fields) { T persitent = (T) cache.get(key); if (persitent == null) { return null; } return getPersistent(persitent, fields); }
@Override public T get(K key) throws GoraException { try { return cache.get(key); } catch (Exception e) { throw new GoraException(e); } }
private void getRecordsFromCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // these get() calls populate the Near Cache, so at the next calls, // the values will be taken from local Near Cache without any remote access String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from cache through client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from cache finished in " + elapsed + " milliseconds"); }
private void getRecordsFromNearCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // since this record has been put to Near Cache before, // it is taken from the local Near Cache without any remote access String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from Near Cache on client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from Near Cache finished in " + elapsed + " milliseconds"); }
private void getRecordsFromCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // these get() calls populate the Near Cache, so at the next calls, // the values will be taken from local Near Cache without any remote access String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from cache through client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from cache finished in " + elapsed + " milliseconds"); }
private void getRecordsFromNearCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // since this record has been put to Near Cache before, // it is taken from the local Near Cache without any remote access String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from Near Cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from Near Cache on client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from Near Cache finished in " + elapsed + " milliseconds"); }
private void getStillOldRecordsFromNearCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // these records have not been invalidated in the Near Cache on client-2, // because client-1 has updated the records and per entry invalidation event is disabled, // so invalidation events are not sent to client-2 (so this record has still its old value) String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from Near Cache must not be updated value " + actualValue + " but old value " + expectedValue + ". Because it must not be invalidated disabled per entry invalidation."; if (VERBOSE) { System.out.println("Get key=" + i + ", old value=" + actualValue + " from Near Cache through client-2 after update"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get old records from Near Cache after update finished in " + elapsed + " milliseconds"); }
private void getInvalidatedRecordsFromNearCacheOnClient2(ICache<Integer, String> clientCache2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // these record have been invalidated at Near Cache on client-2, // because client-1 has updated the records and invalidation events are sent to client-2, // so the records have been taken from the remote cache (not the local Near Cache) through client-2 String actualValue = clientCache2.get(i); String expectedValue = generateValueFromKey(i); try { assert actualValue.equals(expectedValue) : "Taken value from cache should be " + expectedValue + " but it is " + actualValue; } catch (AssertionError assertionError) { System.out.println("Seems that invalidation event for record with key " + i + " has not reached yet"); } if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from cache through client-2 after invalidation"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get invalidated records from Near Cache finished in " + elapsed + " milliseconds"); }
private void getRecordsFromCacheOnClient2(HiDensityNearCacheSupportContext<Integer, String> clientCacheContext1, HiDensityNearCacheSupportContext<Integer, String> clientCacheContext2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // these get() calls populate the Near Cache, so at the next calls, // the values will be taken from local Near Cache without any remote access String actualValue = clientCacheContext2.cache.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from Hi-Density cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from Hi-Density cache through client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from Hi-Density cache finished in " + elapsed + " milliseconds"); System.out.println("Memory usage on client-1: " + clientCacheContext1.memoryManager.getMemoryStats()); System.out.println("Memory usage on client-2: " + clientCacheContext2.memoryManager.getMemoryStats()); }
@TimeStep(prob = 0.2) public void get(ThreadState state) { int key = state.randomInt(keyCount); cache.get(key, expiryPolicy); state.counter.getExpiry++; }
private void getRecordsFromNearCacheOnClient2(HiDensityNearCacheSupportContext<Integer, String> clientCacheContext1, HiDensityNearCacheSupportContext<Integer, String> clientCacheContext2) { long started = System.nanoTime(); for (int i = 0; i < RECORD_COUNT; i++) { // since this record has been put to Near Cache before, // it is taken from the local Near Cache without any remote access String actualValue = clientCacheContext2.cache.get(i); String expectedValue = generateValueFromKey(i); assert actualValue.equals(expectedValue) : "Taken value from cache must be " + expectedValue + " but it is " + actualValue; if (VERBOSE) { System.out.println("Get key=" + i + ", value=" + actualValue + " from Hi-Density Near Cache on client-2"); } } long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started); System.out.println("Get records from Near Cache finished in " + elapsed + " milliseconds"); System.out.println("Memory usage on client-1: " + clientCacheContext1.memoryManager.getMemoryStats()); System.out.println("Memory usage on client-2: " + clientCacheContext2.memoryManager.getMemoryStats()); }
@Override public T get(K key, String[] fields) throws GoraException { try { T persitent = (T) cache.get(key); if (persitent == null) { return null; } return getPersistent(persitent, fields); } catch (Exception e) { throw new GoraException(e); } }
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(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(); }