This commit is contained in:
@@ -213,34 +213,36 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@MultiRun
|
@MultiRun
|
||||||
public V getAndRefresh(K key) {
|
public V getAndRefresh(K key, final int expireSeconds) {
|
||||||
if (key == null) return null;
|
if (key == null) return null;
|
||||||
CacheEntry entry = container.get(key);
|
CacheEntry entry = container.get(key);
|
||||||
if (entry == null || entry.isExpired() || entry.value == null) return null;
|
if (entry == null || entry.isExpired() || entry.value == null) return null;
|
||||||
entry.lastAccessed = (int) (System.currentTimeMillis() / 1000);
|
entry.lastAccessed = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
entry.expireSeconds = expireSeconds;
|
||||||
if (entry.isListCacheType()) return (V) new ArrayList((Collection) entry.value);
|
if (entry.isListCacheType()) return (V) new ArrayList((Collection) entry.value);
|
||||||
if (entry.isSetCacheType()) return (V) new HashSet((Collection) entry.value);
|
if (entry.isSetCacheType()) return (V) new HashSet((Collection) entry.value);
|
||||||
return (V) entry.getValue();
|
return (V) entry.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getAndRefresh(final CompletionHandler<V, K> handler, @DynAttachment final K key) {
|
public void getAndRefresh(final CompletionHandler<V, K> handler, @DynAttachment final K key, final int expireSeconds) {
|
||||||
V rs = getAndRefresh(key);
|
V rs = getAndRefresh(key, expireSeconds);
|
||||||
if (handler != null) handler.completed(rs, key);
|
if (handler != null) handler.completed(rs, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@MultiRun
|
@MultiRun
|
||||||
public void refresh(K key) {
|
public void refresh(K key, final int expireSeconds) {
|
||||||
if (key == null) return;
|
if (key == null) return;
|
||||||
CacheEntry entry = container.get(key);
|
CacheEntry entry = container.get(key);
|
||||||
if (entry == null) return;
|
if (entry == null) return;
|
||||||
entry.lastAccessed = (int) (System.currentTimeMillis() / 1000);
|
entry.lastAccessed = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
entry.expireSeconds = expireSeconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh(final CompletionHandler<Void, K> handler, final K key) {
|
public void refresh(final CompletionHandler<Void, K> handler, final K key, final int expireSeconds) {
|
||||||
refresh(key);
|
refresh(key, expireSeconds);
|
||||||
if (handler != null) handler.completed(null, key);
|
if (handler != null) handler.completed(null, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,13 +327,13 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<V> getCollectionAndRefresh(final K key) {
|
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds) {
|
||||||
return (Collection<V>) getAndRefresh(key);
|
return (Collection<V>) getAndRefresh(key, expireSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getCollectionAndRefresh(final CompletionHandler<Collection<V>, K> handler, @DynAttachment final K key) {
|
public void getCollectionAndRefresh(final CompletionHandler<Collection<V>, K> handler, @DynAttachment final K key, final int expireSeconds) {
|
||||||
if (handler != null) handler.completed(getCollectionAndRefresh(key), key);
|
if (handler != null) handler.completed(getCollectionAndRefresh(key, expireSeconds), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ import java.util.*;
|
|||||||
*
|
*
|
||||||
* @param <K> key的类型
|
* @param <K> key的类型
|
||||||
* @param <V> value的类型
|
* @param <V> value的类型
|
||||||
* <p> 详情见: http://www.redkale.org
|
* <p>
|
||||||
|
* 详情见: http://www.redkale.org
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
public interface CacheSource<K extends Serializable, V extends Object> {
|
public interface CacheSource<K extends Serializable, V extends Object> {
|
||||||
@@ -26,9 +27,9 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
|||||||
|
|
||||||
public V get(final K key);
|
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);
|
public void set(final K key, final V value);
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
|||||||
|
|
||||||
public Collection<V> getCollection(final K key);
|
public Collection<V> getCollection(final K key);
|
||||||
|
|
||||||
public Collection<V> getCollectionAndRefresh(final K key);
|
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds);
|
||||||
|
|
||||||
public void appendListItem(final K key, final V value);
|
public void appendListItem(final K key, final V value);
|
||||||
|
|
||||||
@@ -55,9 +56,9 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
|||||||
|
|
||||||
public void get(final CompletionHandler<V, K> handler, final K key);
|
public void get(final CompletionHandler<V, K> handler, final K key);
|
||||||
|
|
||||||
public void getAndRefresh(final CompletionHandler<V, K> handler, final K key);
|
public void getAndRefresh(final CompletionHandler<V, K> handler, final K key, final int expireSeconds);
|
||||||
|
|
||||||
public void refresh(final CompletionHandler<Void, K> handler, final K key);
|
public void refresh(final CompletionHandler<Void, K> handler, final K key, final int expireSeconds);
|
||||||
|
|
||||||
public void set(final CompletionHandler<Void, K> handler, final K key, final V value);
|
public void set(final CompletionHandler<Void, K> handler, final K key, final V value);
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
|||||||
|
|
||||||
public void getCollection(final CompletionHandler<Collection<V>, K> handler, final K key);
|
public void getCollection(final CompletionHandler<Collection<V>, K> handler, final K key);
|
||||||
|
|
||||||
public void getCollectionAndRefresh(final CompletionHandler<Collection<V>, K> handler, final K key);
|
public void getCollectionAndRefresh(final CompletionHandler<Collection<V>, K> handler, final K key, final int expireSeconds);
|
||||||
|
|
||||||
public void appendListItem(final CompletionHandler<Void, K> handler, final K key, final V value);
|
public void appendListItem(final CompletionHandler<Void, K> handler, final K key, final V value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user