diff --git a/src/org/redkale/service/CacheSourceService.java b/src/org/redkale/service/CacheSourceService.java index 7e40dd239..22e43c63e 100644 --- a/src/org/redkale/service/CacheSourceService.java +++ b/src/org/redkale/service/CacheSourceService.java @@ -213,34 +213,36 @@ public class CacheSourceService implem @Override @MultiRun - public V getAndRefresh(K key) { + public V getAndRefresh(K key, final int expireSeconds) { if (key == null) return null; CacheEntry entry = container.get(key); if (entry == null || entry.isExpired() || entry.value == null) return null; entry.lastAccessed = (int) (System.currentTimeMillis() / 1000); + entry.expireSeconds = expireSeconds; if (entry.isListCacheType()) return (V) new ArrayList((Collection) entry.value); if (entry.isSetCacheType()) return (V) new HashSet((Collection) entry.value); return (V) entry.getValue(); } @Override - public void getAndRefresh(final CompletionHandler handler, @DynAttachment final K key) { - V rs = getAndRefresh(key); + public void getAndRefresh(final CompletionHandler handler, @DynAttachment final K key, final int expireSeconds) { + V rs = getAndRefresh(key, expireSeconds); if (handler != null) handler.completed(rs, key); } @Override @MultiRun - public void refresh(K key) { + public void refresh(K key, final int expireSeconds) { if (key == null) return; CacheEntry entry = container.get(key); if (entry == null) return; entry.lastAccessed = (int) (System.currentTimeMillis() / 1000); + entry.expireSeconds = expireSeconds; } @Override - public void refresh(final CompletionHandler handler, final K key) { - refresh(key); + public void refresh(final CompletionHandler handler, final K key, final int expireSeconds) { + refresh(key, expireSeconds); if (handler != null) handler.completed(null, key); } @@ -325,13 +327,13 @@ public class CacheSourceService implem } @Override - public Collection getCollectionAndRefresh(final K key) { - return (Collection) getAndRefresh(key); + public Collection getCollectionAndRefresh(final K key, final int expireSeconds) { + return (Collection) getAndRefresh(key, expireSeconds); } @Override - public void getCollectionAndRefresh(final CompletionHandler, K> handler, @DynAttachment final K key) { - if (handler != null) handler.completed(getCollectionAndRefresh(key), key); + public void getCollectionAndRefresh(final CompletionHandler, K> handler, @DynAttachment final K key, final int expireSeconds) { + if (handler != null) handler.completed(getCollectionAndRefresh(key, expireSeconds), key); } @Override diff --git a/src/org/redkale/source/CacheSource.java b/src/org/redkale/source/CacheSource.java index 5ca879b13..7fff58b61 100644 --- a/src/org/redkale/source/CacheSource.java +++ b/src/org/redkale/source/CacheSource.java @@ -13,10 +13,11 @@ import java.util.*; * * @param key的类型 * @param value的类型 - *

详情见: http://www.redkale.org + *

+ * 详情见: http://www.redkale.org * @author zhangjx */ -public interface CacheSource { +public interface CacheSource { default boolean isOpen() { return true; @@ -26,9 +27,9 @@ public interface CacheSource { public V get(final K key); - public V getAndRefresh(final K key); + public V getAndRefresh(final K key, final int expireSeconds); - public void refresh(final K key); + public void refresh(final K key, final int expireSeconds); public void set(final K key, final V value); @@ -40,7 +41,7 @@ public interface CacheSource { public Collection getCollection(final K key); - public Collection getCollectionAndRefresh(final K key); + public Collection getCollectionAndRefresh(final K key, final int expireSeconds); public void appendListItem(final K key, final V value); @@ -55,9 +56,9 @@ public interface CacheSource { public void get(final CompletionHandler handler, final K key); - public void getAndRefresh(final CompletionHandler handler, final K key); + public void getAndRefresh(final CompletionHandler handler, final K key, final int expireSeconds); - public void refresh(final CompletionHandler handler, final K key); + public void refresh(final CompletionHandler handler, final K key, final int expireSeconds); public void set(final CompletionHandler handler, final K key, final V value); @@ -69,7 +70,7 @@ public interface CacheSource { public void getCollection(final CompletionHandler, K> handler, final K key); - public void getCollectionAndRefresh(final CompletionHandler, K> handler, final K key); + public void getCollectionAndRefresh(final CompletionHandler, K> handler, final K key, final int expireSeconds); public void appendListItem(final CompletionHandler handler, final K key, final V value);