diff --git a/src/main/java/org/redkale/cache/CacheManager.java b/src/main/java/org/redkale/cache/CacheManager.java index 2f46a39de..7122b7da4 100644 --- a/src/main/java/org/redkale/cache/CacheManager.java +++ b/src/main/java/org/redkale/cache/CacheManager.java @@ -58,7 +58,7 @@ public interface CacheManager { * * @return 数据值 */ - public T localGet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier); + public T localGetSet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier); /** * 本地异步获取缓存数据, 过期返回null @@ -73,7 +73,7 @@ public interface CacheManager { * * @return 数据值 */ - public CompletableFuture localGetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier); + public CompletableFuture localGetSetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier); /** * 本地缓存数据 @@ -171,7 +171,7 @@ public interface CacheManager { * * @return 数据值 */ - public T remoteGet(final String hash, final String key, final Type type, boolean nullable, + public T remoteGetSet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier); /** @@ -187,7 +187,7 @@ public interface CacheManager { * * @return 数据值 */ - public CompletableFuture remoteGetAsync(String hash, String key, Type type, boolean nullable, + public CompletableFuture remoteGetSetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier); /** @@ -325,7 +325,7 @@ public interface CacheManager { * * @return 数据值 */ - public T bothGet(String hash, String key, Type type, boolean nullable, + public T bothGetSet(String hash, String key, Type type, boolean nullable, Duration localExpire, Duration remoteExpire, Supplier supplier); /** @@ -342,7 +342,7 @@ public interface CacheManager { * * @return 数据值 */ - public CompletableFuture bothGetAsync(String hash, String key, Type type, boolean nullable, + public CompletableFuture bothGetSetAsync(String hash, String key, Type type, boolean nullable, Duration localExpire, Duration remoteExpire, Supplier> supplier); /** diff --git a/src/main/java/org/redkale/cache/spi/CacheAction.java b/src/main/java/org/redkale/cache/spi/CacheAction.java index 653d346ab..34f56c2eb 100644 --- a/src/main/java/org/redkale/cache/spi/CacheAction.java +++ b/src/main/java/org/redkale/cache/spi/CacheAction.java @@ -16,8 +16,8 @@ import org.redkale.cache.Cached; import org.redkale.convert.json.JsonConvert; import org.redkale.net.sncp.Sncp; import org.redkale.util.Environment; -import org.redkale.util.TypeToken; import org.redkale.util.MultiHashKey; +import org.redkale.util.TypeToken; /** * @@ -102,9 +102,9 @@ public class CacheAction { public T get(Supplier supplier, Object... args) { if (async) { Supplier supplier0 = supplier; - return (T) manager.bothGetAsync(hash, dynKey.keyFor(args), resultType, nullable, localExpire, remoteExpire, supplier0); + return (T) manager.bothGetSetAsync(hash, dynKey.keyFor(args), resultType, nullable, localExpire, remoteExpire, supplier0); } else { - return manager.bothGet(hash, dynKey.keyFor(args), resultType, nullable, localExpire, remoteExpire, supplier); + return manager.bothGetSet(hash, dynKey.keyFor(args), resultType, nullable, localExpire, remoteExpire, supplier); } } diff --git a/src/main/java/org/redkale/cache/spi/CacheManagerService.java b/src/main/java/org/redkale/cache/spi/CacheManagerService.java index 978e3ba2a..93c06fef2 100644 --- a/src/main/java/org/redkale/cache/spi/CacheManagerService.java +++ b/src/main/java/org/redkale/cache/spi/CacheManagerService.java @@ -157,8 +157,8 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public T localGet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier) { - return get(localSource::hget, localSource::hset, hash, key, type, nullable, expire, supplier); + public T localGetSet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier) { + return getSet(localSource::hget, localSource::hset, hash, key, type, nullable, expire, supplier); } /** @@ -175,8 +175,8 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public CompletableFuture localGetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier) { - return getAsync(localSource::hgetAsync, localSource::hsetAsync, hash, key, type, nullable, expire, supplier); + public CompletableFuture localGetSetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier) { + return getSetAsync(localSource::hgetAsync, localSource::hsetAsync, hash, key, type, nullable, expire, supplier); } /** @@ -263,8 +263,8 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public T remoteGet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier) { - return get(remoteSource::hget, remoteSource::hset, hash, key, type, nullable, expire, supplier); + public T remoteGetSet(final String hash, final String key, final Type type, boolean nullable, Duration expire, Supplier supplier) { + return getSet(remoteSource::hget, remoteSource::hset, hash, key, type, nullable, expire, supplier); } /** @@ -281,8 +281,8 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public CompletableFuture remoteGetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier) { - return getAsync(remoteSource::hgetAsync, remoteSource::hsetAsync, hash, key, type, nullable, expire, supplier); + public CompletableFuture remoteGetSetAsync(String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier) { + return getSetAsync(remoteSource::hgetAsync, remoteSource::hsetAsync, hash, key, type, nullable, expire, supplier); } /** @@ -398,19 +398,19 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public T bothGet(final String hash, final String key, final Type type, boolean nullable, + public T bothGetSet(final String hash, final String key, final Type type, boolean nullable, Duration localExpire, Duration remoteExpire, Supplier supplier) { if (!enabled) { return supplier.get(); } if (localExpire == null) { //只有远程缓存 Objects.requireNonNull(remoteExpire); - return remoteGet(hash, key, type, nullable, remoteExpire, supplier); + return remoteGetSet(hash, key, type, nullable, remoteExpire, supplier); } if (remoteExpire == null) { //只有本地缓存 - return localGet(hash, key, type, nullable, localExpire, supplier); + return localGetSet(hash, key, type, nullable, localExpire, supplier); } - return get(this::bothGetCache, (h, k, t, v) -> { + return getSet(this::bothGetCache, (h, k, t, v) -> { localSource.hset(h, k, t, v); if (remoteSource != null) { remoteSource.hset(h, k, t, CacheValue.create(v.getValue(), remoteExpire)); @@ -433,19 +433,19 @@ public class CacheManagerService implements CacheManager, Service { * @return 数据值 */ @Override - public CompletableFuture bothGetAsync(String hash, String key, Type type, boolean nullable, + public CompletableFuture bothGetSetAsync(String hash, String key, Type type, boolean nullable, Duration localExpire, Duration remoteExpire, Supplier> supplier) { if (!enabled) { return supplier.get(); } if (localExpire == null) { //只有远程缓存 Objects.requireNonNull(remoteExpire); - return remoteGetAsync(hash, key, type, nullable, remoteExpire, supplier); + return remoteGetSetAsync(hash, key, type, nullable, remoteExpire, supplier); } if (remoteExpire == null) { //只有本地缓存 - return localGetAsync(hash, key, type, nullable, localExpire, supplier); + return localGetSetAsync(hash, key, type, nullable, localExpire, supplier); } - return getAsync(this::bothGetCacheAsync, (h, k, t, v) -> { + return getSetAsync(this::bothGetCacheAsync, (h, k, t, v) -> { localSource.hset(h, k, t, v); if (remoteSource != null) { return remoteSource.hsetAsync(h, k, t, CacheValue.create(v.getValue(), remoteExpire)); @@ -559,7 +559,7 @@ public class CacheManagerService implements CacheManager, Service { * * @return 数据值 */ - protected T get(GetterFunc> getter, SetterSyncFunc setter, + protected T getSet(GetterFunc> getter, SetterSyncFunc setter, String hash, String key, Type type, boolean nullable, Duration expire, Supplier supplier) { checkEnable(); Objects.requireNonNull(expire); @@ -604,7 +604,7 @@ public class CacheManagerService implements CacheManager, Service { * * @return 数据值 */ - protected CompletableFuture getAsync(GetterFunc>> getter, SetterAsyncFunc setter, + protected CompletableFuture getSetAsync(GetterFunc>> getter, SetterAsyncFunc setter, String hash, String key, Type type, boolean nullable, Duration expire, Supplier> supplier) { checkEnable(); Objects.requireNonNull(supplier); diff --git a/src/test/java/org/redkale/test/cache/CacheManagerTest.java b/src/test/java/org/redkale/test/cache/CacheManagerTest.java index c067c2fea..298932a82 100644 --- a/src/test/java/org/redkale/test/cache/CacheManagerTest.java +++ b/src/test/java/org/redkale/test/cache/CacheManagerTest.java @@ -64,7 +64,7 @@ public class CacheManagerTest { CountDownLatch cdl = new CountDownLatch(count); for (int i = 0; i < count; i++) { new Thread(() -> { - manager.bothGet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); + manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); cdl.countDown(); }).start(); } @@ -72,14 +72,14 @@ public class CacheManagerTest { } Assertions.assertEquals(1, ParallelBean.c1.get()); Utility.sleep(200); - manager.bothGet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); + manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); Assertions.assertEquals(1, ParallelBean.c1.get()); Utility.sleep(200); { CountDownLatch cdl = new CountDownLatch(count); for (int i = 0; i < count; i++) { new Thread(() -> { - manager.bothGet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); + manager.bothGetSet("ParallelBean", "name", String.class, false, localExpire, remoteExpire, () -> bean.getName()); cdl.countDown(); }).start(); }