From 0918af71d29eb0bee652ea6293bbf272408e4f37 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Wed, 5 Jul 2017 15:18:16 +0800 Subject: [PATCH] =?UTF-8?q?CacheSource=E5=A2=9E=E5=8A=A0getKeySize?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/source/CacheMemorySource.java | 13 +++++++++++-- src/org/redkale/source/CacheSource.java | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/org/redkale/source/CacheMemorySource.java b/src/org/redkale/source/CacheMemorySource.java index a35f0e6e0..c8af82fad 100644 --- a/src/org/redkale/source/CacheMemorySource.java +++ b/src/org/redkale/source/CacheMemorySource.java @@ -348,13 +348,13 @@ public class CacheMemorySource extends } @Override - public long getCollectionSize(final K key) { + public int getCollectionSize(final K key) { Collection collection = (Collection) get(key); return collection == null ? 0 : collection.size(); } @Override - public CompletableFuture getCollectionSizeAsync(final K key) { + public CompletableFuture getCollectionSizeAsync(final K key) { return CompletableFuture.supplyAsync(() -> getCollectionSize(key), getExecutor()); } @@ -443,6 +443,11 @@ public class CacheMemorySource extends return new ArrayList<>(container.keySet()); } + @Override + public int getKeySize() { + return container.size(); + } + @Override public CompletableFuture>> queryListAsync() { return CompletableFuture.completedFuture(new ArrayList<>(container.values())); @@ -458,4 +463,8 @@ public class CacheMemorySource extends return CompletableFuture.completedFuture(new ArrayList<>(container.keySet())); } + @Override + public CompletableFuture getKeySizeAsync() { + return CompletableFuture.completedFuture(container.size()); + } } diff --git a/src/org/redkale/source/CacheSource.java b/src/org/redkale/source/CacheSource.java index fed433dcb..72529daf2 100644 --- a/src/org/redkale/source/CacheSource.java +++ b/src/org/redkale/source/CacheSource.java @@ -45,7 +45,7 @@ public interface CacheSource { public Collection getCollection(final K key); - public long getCollectionSize(final K key); + public int getCollectionSize(final K key); public Collection getCollectionAndRefresh(final K key, final int expireSeconds); @@ -59,6 +59,8 @@ public interface CacheSource { public List queryKeys(); + public int getKeySize(); + public List> queryList(); //---------------------- CompletableFuture 异步版 --------------------------------- @@ -80,7 +82,7 @@ public interface CacheSource { public CompletableFuture> getCollectionAsync(final K key); - public CompletableFuture getCollectionSizeAsync(final K key); + public CompletableFuture getCollectionSizeAsync(final K key); public CompletableFuture> getCollectionAndRefreshAsync(final K key, final int expireSeconds); @@ -94,6 +96,8 @@ public interface CacheSource { public CompletableFuture> queryKeysAsync(); + public CompletableFuture getKeySizeAsync(); + public CompletableFuture>> queryListAsync(); default CompletableFuture isOpenAsync() {