@Test void get_witValueLoaderAndExistingValue_doesNotCallValueLoader() throws Exception { MemcachedClientIF client = mock(MemcachedClientIF.class); SimpleSpringMemcached cache = new SimpleSpringMemcached(client, "test"); when(client.get("myKey")).thenReturn("existingValue"); String value = cache.get("myKey", () -> { throw new UnsupportedOperationException("Should not be called"); }); assertThat(value).isEqualTo("existingValue"); }
@Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; }
SimpleSpringMemcached implements Cache { @Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; } }
SimpleSpringMemcached implements Cache { @Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; } SimpleSpringMemcached(MemcachedClientIF memcachedClientIF, String cacheName); }
SimpleSpringMemcached implements Cache { @Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; } SimpleSpringMemcached(MemcachedClientIF memcachedClientIF, String cacheName); @Override String getName(); @Override Object getNativeCache(); @Override ValueWrapper get(Object key); @Override T get(Object key, Class<T> type); @SuppressWarnings("unchecked") @Override T get(Object key, Callable<T> valueLoader); @Override void put(Object key, Object value); @Override ValueWrapper putIfAbsent(Object key, Object value); @Override void evict(Object key); @Override void clear(); void setExpiration(int expiration); }
SimpleSpringMemcached implements Cache { @Override public ValueWrapper get(Object key) { Assert.notNull(key, "key parameter is mandatory"); Assert.isAssignable(String.class, key.getClass()); Object result = this.memcachedClientIF.get((String) key); return result != null ? new SimpleValueWrapper(result) : null; } SimpleSpringMemcached(MemcachedClientIF memcachedClientIF, String cacheName); @Override String getName(); @Override Object getNativeCache(); @Override ValueWrapper get(Object key); @Override T get(Object key, Class<T> type); @SuppressWarnings("unchecked") @Override T get(Object key, Callable<T> valueLoader); @Override void put(Object key, Object value); @Override ValueWrapper putIfAbsent(Object key, Object value); @Override void evict(Object key); @Override void clear(); void setExpiration(int expiration);  }