CacheSource增加getKeySize方法

This commit is contained in:
Redkale
2017-07-05 15:18:16 +08:00
parent 275befa330
commit 0918af71d2
2 changed files with 17 additions and 4 deletions

View File

@@ -348,13 +348,13 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
}
@Override
public long getCollectionSize(final K key) {
public int getCollectionSize(final K key) {
Collection<V> collection = (Collection<V>) get(key);
return collection == null ? 0 : collection.size();
}
@Override
public CompletableFuture<Long> getCollectionSizeAsync(final K key) {
public CompletableFuture<Integer> getCollectionSizeAsync(final K key) {
return CompletableFuture.supplyAsync(() -> getCollectionSize(key), getExecutor());
}
@@ -443,6 +443,11 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
return new ArrayList<>(container.keySet());
}
@Override
public int getKeySize() {
return container.size();
}
@Override
public CompletableFuture<List<CacheEntry<K, Object>>> queryListAsync() {
return CompletableFuture.completedFuture(new ArrayList<>(container.values()));
@@ -458,4 +463,8 @@ public class CacheMemorySource<K extends Serializable, V extends Object> extends
return CompletableFuture.completedFuture(new ArrayList<>(container.keySet()));
}
@Override
public CompletableFuture<Integer> getKeySizeAsync() {
return CompletableFuture.completedFuture(container.size());
}
}

View File

@@ -45,7 +45,7 @@ public interface CacheSource<K extends Serializable, V extends Object> {
public Collection<V> getCollection(final K key);
public long getCollectionSize(final K key);
public int getCollectionSize(final K key);
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds);
@@ -59,6 +59,8 @@ public interface CacheSource<K extends Serializable, V extends Object> {
public List<K> queryKeys();
public int getKeySize();
public List<CacheEntry<K, Object>> queryList();
//---------------------- CompletableFuture 异步版 ---------------------------------
@@ -80,7 +82,7 @@ public interface CacheSource<K extends Serializable, V extends Object> {
public CompletableFuture<Collection<V>> getCollectionAsync(final K key);
public CompletableFuture<Long> getCollectionSizeAsync(final K key);
public CompletableFuture<Integer> getCollectionSizeAsync(final K key);
public CompletableFuture<Collection<V>> getCollectionAndRefreshAsync(final K key, final int expireSeconds);
@@ -94,6 +96,8 @@ public interface CacheSource<K extends Serializable, V extends Object> {
public CompletableFuture<List<K>> queryKeysAsync();
public CompletableFuture<Integer> getKeySizeAsync();
public CompletableFuture<List<CacheEntry<K, Object>>> queryListAsync();
default CompletableFuture<Boolean> isOpenAsync() {