@Test public void getLoadsValueFromLoader() throws ConnectionException, IOException { int key = 3; int value = 5; doReturn(null).when(client).get(serializer.serialize(key)); doReturn(value).when(cacheLoader).load(key); int actualValue = cache.get(key); assertEquals(value, actualValue); verify(client).set(serializer.serialize(key), serializer.serialize(value)); }
@Override @SuppressWarnings("unchecked") public V get(final K key) { try { final byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.get(serializedKey); V value = null; if(serializedValue != null && serializedValue.length > 0){ value = (V) serializer.deserialize(serializedValue); } if (value == null) { stats.incrementMissCount(); value = cacheLoader.load(key); if (value != null) { serializedValue = serializer.serialize(value); client.set(serializedKey, serializedValue); stats.incrementLoadCount(); } } else { stats.incrementHitCount(); } return value; } catch (ConnectionException|IOException e) { throw new RedisCacheException(e); } }
RedisCache extends AbstractCache<K, V> { @Override @SuppressWarnings("unchecked") public V get(final K key) { try { final byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.get(serializedKey); V value = null; if(serializedValue != null && serializedValue.length > 0){ value = (V) serializer.deserialize(serializedValue); } if (value == null) { stats.incrementMissCount(); value = cacheLoader.load(key); if (value != null) { serializedValue = serializer.serialize(value); client.set(serializedKey, serializedValue); stats.incrementLoadCount(); } } else { stats.incrementHitCount(); } return value; } catch (ConnectionException|IOException e) { throw new RedisCacheException(e); } } }
RedisCache extends AbstractCache<K, V> { @Override @SuppressWarnings("unchecked") public V get(final K key) { try { final byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.get(serializedKey); V value = null; if(serializedValue != null && serializedValue.length > 0){ value = (V) serializer.deserialize(serializedValue); } if (value == null) { stats.incrementMissCount(); value = cacheLoader.load(key); if (value != null) { serializedValue = serializer.serialize(value); client.set(serializedKey, serializedValue); stats.incrementLoadCount(); } } else { stats.incrementHitCount(); } return value; } catch (ConnectionException|IOException e) { throw new RedisCacheException(e); } } RedisCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      Serializer<Object> serializer, Client client); }
RedisCache extends AbstractCache<K, V> { @Override @SuppressWarnings("unchecked") public V get(final K key) { try { final byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.get(serializedKey); V value = null; if(serializedValue != null && serializedValue.length > 0){ value = (V) serializer.deserialize(serializedValue); } if (value == null) { stats.incrementMissCount(); value = cacheLoader.load(key); if (value != null) { serializedValue = serializer.serialize(value); client.set(serializedKey, serializedValue); stats.incrementLoadCount(); } } else { stats.incrementHitCount(); } return value; } catch (ConnectionException|IOException e) { throw new RedisCacheException(e); } } RedisCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      Serializer<Object> serializer, Client client); @Override void put(final K key, final V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); @Override @SuppressWarnings("unchecked") V get(final K key); @Override @SuppressWarnings("unchecked") V invalidate(final K key); @Override boolean contains(final K key); @Override void clear(); @Override long size(); @Override CacheStats stats(); }
RedisCache extends AbstractCache<K, V> { @Override @SuppressWarnings("unchecked") public V get(final K key) { try { final byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.get(serializedKey); V value = null; if(serializedValue != null && serializedValue.length > 0){ value = (V) serializer.deserialize(serializedValue); } if (value == null) { stats.incrementMissCount(); value = cacheLoader.load(key); if (value != null) { serializedValue = serializer.serialize(value); client.set(serializedKey, serializedValue); stats.incrementLoadCount(); } } else { stats.incrementHitCount(); } return value; } catch (ConnectionException|IOException e) { throw new RedisCacheException(e); } } RedisCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      Serializer<Object> serializer, Client client); @Override void put(final K key, final V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); @Override @SuppressWarnings("unchecked") V get(final K key); @Override @SuppressWarnings("unchecked") V invalidate(final K key); @Override boolean contains(final K key); @Override void clear(); @Override long size(); @Override CacheStats stats();  }