Skip to content

Commit

Permalink
(incompatible) GET/GET_ALL method of RefreshCache will not trigger re…
Browse files Browse the repository at this point in the history
…fresh.

All upper case method of Cache interface should simply access the cache system and have no side-effect.
  • Loading branch information
areyouok committed Aug 4, 2019
1 parent 3e57bff commit d280196
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static <K, V> V computeIfAbsentImpl(K key, Function<K, V> loader, boolean cacheN
CacheGetResult<V> r;
if (cache instanceof RefreshCache) {
RefreshCache<K, V> refreshCache = ((RefreshCache<K, V>) cache);
r = refreshCache.getTargetCache().GET(key);
r = refreshCache.GET(key);
refreshCache.addOrUpdateRefreshTask(key, newLoader);
} else {
r = cache.GET(key);
Expand Down
13 changes: 5 additions & 8 deletions jetcache-core/src/main/java/com/alicp/jetcache/RefreshCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.slf4j.LoggerFactory;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -126,21 +123,21 @@ protected void addOrUpdateRefreshTask(K key, CacheLoader<K,V> loader) {
}

@Override
public CacheGetResult<V> GET(K key) {
public V get(K key) throws CacheInvokeException {
if (config.getRefreshPolicy() != null && hasLoader()) {
addOrUpdateRefreshTask(key, null);
}
return cache.GET(key);
return super.get(key);
}

@Override
public MultiGetResult<K, V> GET_ALL(Set<? extends K> keys) {
public Map<K, V> getAll(Set<? extends K> keys) throws CacheInvokeException {
if (config.getRefreshPolicy() != null && hasLoader()) {
for (K key : keys) {
addOrUpdateRefreshTask(key, null);
}
}
return cache.GET_ALL(keys);
return super.getAll(keys);
}

class RefreshTask implements Runnable {
Expand Down

0 comments on commit d280196

Please sign in to comment.