bothDelAsync(String key) {
- return bothDelAsync(DEFAULT_HASH, key);
+ return bothDelAsync(DEFAULT_SCHEMA, key);
}
}
diff --git a/src/main/java/org/redkale/cached/spi/CachedAction.java b/src/main/java/org/redkale/cached/spi/CachedAction.java
index abea09a24..bf87d2c35 100644
--- a/src/main/java/org/redkale/cached/spi/CachedAction.java
+++ b/src/main/java/org/redkale/cached/spi/CachedAction.java
@@ -96,9 +96,9 @@ public class CachedAction {
}
void init(ResourceFactory resourceFactory, Object service) {
- this.hash = cached.getHash().trim().isEmpty() || CachedManager.DEFAULT_HASH.equals(cached.getHash())
- ? CachedManager.DEFAULT_HASH
- : environment.getPropertyValue(cached.getHash());
+ this.hash = cached.getSchema().trim().isEmpty() || CachedManager.DEFAULT_SCHEMA.equals(cached.getSchema())
+ ? CachedManager.DEFAULT_SCHEMA
+ : environment.getPropertyValue(cached.getSchema());
String key = environment.getPropertyValue(cached.getKey());
this.templetKey = key;
if (key.startsWith("@")) { // 动态加载缓存key生成器
diff --git a/src/main/java/org/redkale/cached/spi/CachedEntry.java b/src/main/java/org/redkale/cached/spi/CachedEntry.java
index 8c5ba3d0b..9c31dd325 100644
--- a/src/main/java/org/redkale/cached/spi/CachedEntry.java
+++ b/src/main/java/org/redkale/cached/spi/CachedEntry.java
@@ -20,7 +20,7 @@ public class CachedEntry {
private String key;
- private String hash;
+ private String schema;
private String localExpire;
@@ -34,7 +34,7 @@ public class CachedEntry {
public CachedEntry(DynForCached cached) {
this.key = cached.key();
- this.hash = cached.hash();
+ this.schema = cached.schema();
this.localExpire = cached.localExpire();
this.remoteExpire = cached.remoteExpire();
this.timeUnit = cached.timeUnit();
@@ -43,7 +43,7 @@ public class CachedEntry {
public CachedEntry(Cached cached) {
this.key = cached.key();
- this.hash = cached.hash();
+ this.schema = cached.schema();
this.localExpire = cached.localExpire();
this.remoteExpire = cached.remoteExpire();
this.timeUnit = cached.timeUnit();
@@ -54,8 +54,8 @@ public class CachedEntry {
return key;
}
- public String getHash() {
- return hash;
+ public String getSchema() {
+ return schema;
}
public String getLocalExpire() {
diff --git a/src/main/java/org/redkale/cached/spi/CachedKeyGenerator.java b/src/main/java/org/redkale/cached/spi/CachedKeyGenerator.java
index 691487c58..51131104a 100644
--- a/src/main/java/org/redkale/cached/spi/CachedKeyGenerator.java
+++ b/src/main/java/org/redkale/cached/spi/CachedKeyGenerator.java
@@ -10,7 +10,7 @@ import org.redkale.util.MultiHashKey;
/**
* 缓存key生成器
*
- * @see org.redkale.cache.Cached#key()
+ * @see org.redkale.cached.Cached#key()
*
* 详情见: https://redkale.org
*
@@ -22,8 +22,8 @@ public interface CachedKeyGenerator {
/**
* 根据service和方法名生成key
*
- * @param target Service对象
- * @param action CacheAction对象
+ * @param target 依附对象
+ * @param action {@link org.redkale.cached.spi.CachedAction}对象
* @param params 参数值
* @return key值
*/
@@ -32,15 +32,15 @@ public interface CachedKeyGenerator {
/**
* 生成器的名字
*
- * @see org.redkale.cache.Cached#key()
+ * @see org.redkale.cached.Cached#key()
*
* @return name
*/
public String name();
/**
- * 根据MultiHashKey生成一个CacheKeyGenerator
- * @param key MultiHashKey 不能为空
+ * 根据MultiHashKey生成一个CachedKeyGenerator
+ * @param key {@link org.redkale.util.MultiHashKey} 不能为空
* @return CachedKeyGenerator
*/
public static CachedKeyGenerator create(MultiHashKey key) {
diff --git a/src/main/java/org/redkale/cached/spi/CachedManagerService.java b/src/main/java/org/redkale/cached/spi/CachedManagerService.java
index 778abcb0a..a2662bc67 100644
--- a/src/main/java/org/redkale/cached/spi/CachedManagerService.java
+++ b/src/main/java/org/redkale/cached/spi/CachedManagerService.java
@@ -58,11 +58,11 @@ public class CachedManagerService implements CachedManager, Service {
// 本地缓存Source
protected final CacheMemorySource localSource = new CacheMemorySource("cache-local");
- // 缓存hash集合, 用于定时遍历删除过期数据
+ // 缓存schema集合, 用于定时遍历删除过期数据
protected final ConcurrentSkipListSet hashNames = new ConcurrentSkipListSet<>();
// 缓存无效时使用的同步锁
- private final ConcurrentHashMap syncLock = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap syncLockMap = new ConcurrentHashMap<>();
// 缓存无效时使用的异步锁
private final ConcurrentHashMap asyncLockMap = new ConcurrentHashMap<>();
@@ -132,8 +132,8 @@ public class CachedManagerService implements CachedManager, Service {
return enabled;
}
- public CachedManagerService addHash(String hash) {
- this.hashNames.add(hash);
+ public CachedManagerService addSchema(String schema) {
+ this.hashNames.add(schema);
return this;
}
@@ -158,22 +158,22 @@ public class CachedManagerService implements CachedManager, Service {
* 本地获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @return 数据值
*/
@Override
- public T localGet(final String hash, final String key, final Type type) {
+ public T localGet(final String schema, final String key, final Type type) {
checkEnable();
- return CachedValue.get(localSource.get(idFor(hash, key), loadCacheType(type)));
+ return CachedValue.get(localSource.get(idFor(schema, key), loadCacheType(type)));
}
/**
* 本地获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -183,7 +183,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public T localGetSet(
- final String hash,
+ final String schema,
final String key,
final Type type,
boolean nullable,
@@ -192,7 +192,7 @@ public class CachedManagerService implements CachedManager, Service {
return getSet(
(id, ex, ct) -> localSource.get(id, ct),
this::localSetCache,
- hash,
+ schema,
key,
type,
nullable,
@@ -204,7 +204,7 @@ public class CachedManagerService implements CachedManager, Service {
* 本地异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -214,7 +214,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public CompletableFuture localGetSetAsync(
- String hash,
+ String schema,
String key,
Type type,
boolean nullable,
@@ -223,7 +223,7 @@ public class CachedManagerService implements CachedManager, Service {
return getSetAsync(
(id, ex, ct) -> localSource.getAsync(id, ct),
this::localSetCacheAsync,
- hash,
+ schema,
key,
type,
nullable,
@@ -235,28 +235,28 @@ public class CachedManagerService implements CachedManager, Service {
* 本地缓存数据
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param value 数据值
* @param expire 过期时长,Duration.ZERO为永不过期
*/
@Override
- public void localSet(String hash, String key, Type type, T value, Duration expire) {
- setCache(localSource, hash, key, type, value, expire);
+ public void localSet(String schema, String key, Type type, T value, Duration expire) {
+ setCache(localSource, schema, key, type, value, expire);
}
/**
* 本地删除缓存数据
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return 删除数量
*/
@Override
- public long localDel(String hash, String key) {
+ public long localDel(String schema, String key) {
checkEnable();
- return localSource.del(idFor(hash, key));
+ return localSource.del(idFor(schema, key));
}
// -------------------------------------- 远程缓存 --------------------------------------
@@ -264,30 +264,30 @@ public class CachedManagerService implements CachedManager, Service {
* 远程获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @return 数据值
*/
@Override
- public T remoteGet(final String hash, final String key, final Type type) {
+ public T remoteGet(final String schema, final String key, final Type type) {
checkEnable();
- return CachedValue.get(remoteSource.get(idFor(hash, key), loadCacheType(type)));
+ return CachedValue.get(remoteSource.get(idFor(schema, key), loadCacheType(type)));
}
/**
* 远程异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @return 数据值
*/
@Override
- public CompletableFuture remoteGetAsync(final String hash, final String key, final Type type) {
+ public CompletableFuture remoteGetAsync(final String schema, final String key, final Type type) {
checkEnable();
- CompletableFuture> future = remoteSource.getAsync(idFor(hash, key), loadCacheType(type));
+ CompletableFuture> future = remoteSource.getAsync(idFor(schema, key), loadCacheType(type));
return future.thenApply(CachedValue::get);
}
@@ -295,7 +295,7 @@ public class CachedManagerService implements CachedManager, Service {
* 远程获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -305,7 +305,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public T remoteGetSet(
- final String hash,
+ final String schema,
final String key,
final Type type,
boolean nullable,
@@ -314,7 +314,7 @@ public class CachedManagerService implements CachedManager, Service {
return getSet(
(id, ex, ct) -> remoteSource.get(id, ct),
this::remoteSetCache,
- hash,
+ schema,
key,
type,
nullable,
@@ -326,7 +326,7 @@ public class CachedManagerService implements CachedManager, Service {
* 远程异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -336,7 +336,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public CompletableFuture remoteGetSetAsync(
- String hash,
+ String schema,
String key,
Type type,
boolean nullable,
@@ -345,7 +345,7 @@ public class CachedManagerService implements CachedManager, Service {
return getSetAsync(
(id, ex, ct) -> remoteSource.getAsync(id, ct),
this::remoteSetCacheAsync,
- hash,
+ schema,
key,
type,
nullable,
@@ -357,56 +357,56 @@ public class CachedManagerService implements CachedManager, Service {
* 远程缓存数据
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param value 数据值
* @param expire 过期时长,Duration.ZERO为永不过期
*/
@Override
- public void remoteSet(final String hash, final String key, final Type type, final T value, Duration expire) {
- setCache(remoteSource, hash, key, type, value, expire);
+ public void remoteSet(final String schema, final String key, final Type type, final T value, Duration expire) {
+ setCache(remoteSource, schema, key, type, value, expire);
}
/**
* 远程异步缓存数据
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param value 数据值
* @param expire 过期时长,Duration.ZERO为永不过期
*/
@Override
- public CompletableFuture remoteSetAsync(String hash, String key, Type type, T value, Duration expire) {
- return setCacheAsync(remoteSource, hash, key, type, value, expire);
+ public CompletableFuture remoteSetAsync(String schema, String key, Type type, T value, Duration expire) {
+ return setCacheAsync(remoteSource, schema, key, type, value, expire);
}
/**
* 远程删除缓存数据
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return 删除数量
*/
@Override
- public long remoteDel(String hash, String key) {
+ public long remoteDel(String schema, String key) {
checkEnable();
- return remoteSource.del(idFor(hash, key));
+ return remoteSource.del(idFor(schema, key));
}
/**
* 远程异步删除缓存数据
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return 删除数量
*/
@Override
- public CompletableFuture remoteDelAsync(String hash, String key) {
+ public CompletableFuture remoteDelAsync(String schema, String key) {
checkEnable();
- return remoteSource.delAsync(idFor(hash, key));
+ return remoteSource.delAsync(idFor(schema, key));
}
// -------------------------------------- both缓存 --------------------------------------
@@ -414,35 +414,35 @@ public class CachedManagerService implements CachedManager, Service {
* 远程获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @return 数据值
*/
@Override
- public T bothGet(final String hash, final String key, final Type type) {
- return CachedValue.get(bothGetCache(hash, key, (Duration) null, type));
+ public T bothGet(final String schema, final String key, final Type type) {
+ return CachedValue.get(bothGetCache(schema, key, (Duration) null, type));
}
/**
* 远程异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @return 数据值
*/
@Override
- public CompletableFuture bothGetAsync(final String hash, final String key, final Type type) {
- return bothGetCacheAsync(hash, key, (Duration) null, type).thenApply(CachedValue::get);
+ public CompletableFuture bothGetAsync(final String schema, final String key, final Type type) {
+ return bothGetCacheAsync(schema, key, (Duration) null, type).thenApply(CachedValue::get);
}
/**
* 远程获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -453,7 +453,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public T bothGetSet(
- final String hash,
+ final String schema,
final String key,
final Type type,
boolean nullable,
@@ -471,11 +471,11 @@ public class CachedManagerService implements CachedManager, Service {
}
if (remoteExpire == null) { // 只有本地缓存
Objects.requireNonNull(localExpire);
- return localGetSet(hash, key, type, nullable, localExpire, supplier);
+ return localGetSet(schema, key, type, nullable, localExpire, supplier);
}
if (localExpire == null) { // 只有远程缓存
Objects.requireNonNull(remoteExpire);
- return remoteGetSet(hash, key, type, nullable, remoteExpire, supplier);
+ return remoteGetSet(schema, key, type, nullable, remoteExpire, supplier);
}
return getSet(
this::bothGetCache,
@@ -485,7 +485,7 @@ public class CachedManagerService implements CachedManager, Service {
remoteSetCache(i, remoteExpire, t, v);
}
},
- hash,
+ schema,
key,
type,
nullable,
@@ -497,7 +497,7 @@ public class CachedManagerService implements CachedManager, Service {
* 远程异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -508,7 +508,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public CompletableFuture bothGetSetAsync(
- String hash,
+ String schema,
String key,
Type type,
boolean nullable,
@@ -524,11 +524,11 @@ public class CachedManagerService implements CachedManager, Service {
}
if (remoteExpire == null) { // 只有本地缓存
Objects.requireNonNull(localExpire);
- return localGetSetAsync(hash, key, type, nullable, localExpire, supplier);
+ return localGetSetAsync(schema, key, type, nullable, localExpire, supplier);
}
if (localExpire == null) { // 只有远程缓存
Objects.requireNonNull(remoteExpire);
- return remoteGetSetAsync(hash, key, type, nullable, remoteExpire, supplier);
+ return remoteGetSetAsync(schema, key, type, nullable, remoteExpire, supplier);
}
return getSetAsync(
this::bothGetCacheAsync,
@@ -540,7 +540,7 @@ public class CachedManagerService implements CachedManager, Service {
return CompletableFuture.completedFuture(null);
}
},
- hash,
+ schema,
key,
type,
nullable,
@@ -552,7 +552,7 @@ public class CachedManagerService implements CachedManager, Service {
* 远程缓存数据
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param value 数据值
@@ -561,7 +561,7 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public void bothSet(
- final String hash,
+ final String schema,
final String key,
final Type type,
final T value,
@@ -569,13 +569,13 @@ public class CachedManagerService implements CachedManager, Service {
Duration remoteExpire) {
checkEnable();
if (localExpire != null) {
- setCache(localSource, hash, key, type, value, localExpire);
+ setCache(localSource, schema, key, type, value, localExpire);
}
if (remoteExpire != null && remoteSource != null) {
- setCache(remoteSource, hash, key, type, value, remoteExpire);
+ setCache(remoteSource, schema, key, type, value, remoteExpire);
}
if (remoteSource != null && broadcastable) {
- remoteSource.publish(CACHE_CHANNEL_TOPIC, new CachedEventMessage(idFor(hash, key)));
+ remoteSource.publish(CACHE_CHANNEL_TOPIC, new CachedEventMessage(idFor(schema, key)));
}
}
@@ -583,7 +583,7 @@ public class CachedManagerService implements CachedManager, Service {
* 远程异步缓存数据
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param value 数据值
@@ -593,18 +593,18 @@ public class CachedManagerService implements CachedManager, Service {
*/
@Override
public CompletableFuture bothSetAsync(
- String hash, String key, Type type, T value, Duration localExpire, Duration remoteExpire) {
+ String schema, String key, Type type, T value, Duration localExpire, Duration remoteExpire) {
checkEnable();
if (localExpire != null) {
- setCache(localSource, hash, key, type, value, localExpire);
+ setCache(localSource, schema, key, type, value, localExpire);
}
CompletableFuture future = CompletableFuture.completedFuture(null);
if (remoteSource != null && remoteExpire != null) {
- future = setCacheAsync(remoteSource, hash, key, type, value, remoteExpire);
+ future = setCacheAsync(remoteSource, schema, key, type, value, remoteExpire);
}
if (remoteSource != null && broadcastable) {
future = future.thenCompose(r -> remoteSource
- .publishAsync(CACHE_CHANNEL_TOPIC, new CachedEventMessage(idFor(hash, key)))
+ .publishAsync(CACHE_CHANNEL_TOPIC, new CachedEventMessage(idFor(schema, key)))
.thenApply(n -> r));
}
return future;
@@ -613,14 +613,14 @@ public class CachedManagerService implements CachedManager, Service {
/**
* 远程删除缓存数据
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return 删除数量
*/
@Override
- public long bothDel(String hash, String key) {
+ public long bothDel(String schema, String key) {
checkEnable();
- String id = idFor(hash, key);
+ String id = idFor(schema, key);
long v = localSource.del(id);
if (remoteSource != null) {
v = remoteSource.del(id);
@@ -634,14 +634,14 @@ public class CachedManagerService implements CachedManager, Service {
/**
* 远程异步删除缓存数据
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return 删除数量
*/
@Override
- public CompletableFuture bothDelAsync(String hash, String key) {
+ public CompletableFuture bothDelAsync(String schema, String key) {
checkEnable();
- String id = idFor(hash, key);
+ String id = idFor(schema, key);
long v = localSource.del(id); // 内存操作,无需异步
if (remoteSource != null) {
return remoteSource.delAsync(id).thenCompose(r -> {
@@ -663,7 +663,7 @@ public class CachedManagerService implements CachedManager, Service {
* @param 泛型
* @param getter 获取数据函数
* @param setter 设置数据函数
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -674,7 +674,7 @@ public class CachedManagerService implements CachedManager, Service {
protected T getSet(
GetterFunc> getter,
SetterSyncFunc setter,
- String hash,
+ String schema,
String key,
Type type,
boolean nullable,
@@ -684,7 +684,7 @@ public class CachedManagerService implements CachedManager, Service {
Objects.requireNonNull(expire);
Objects.requireNonNull(supplier);
final Type cacheType = loadCacheType(type);
- final String id = idFor(hash, key);
+ final String id = idFor(schema, key);
CachedValue cacheVal = getter.get(id, expire, cacheType);
if (CachedValue.isValid(cacheVal)) {
return cacheVal.getVal();
@@ -707,11 +707,11 @@ public class CachedManagerService implements CachedManager, Service {
}
return newCacheVal;
};
- cacheVal = syncLock.computeIfAbsent(id, func);
+ cacheVal = syncLockMap.computeIfAbsent(id, func);
try {
return CachedValue.get(cacheVal);
} finally {
- syncLock.remove(id);
+ syncLockMap.remove(id);
}
}
@@ -721,7 +721,7 @@ public class CachedManagerService implements CachedManager, Service {
* @param 泛型
* @param getter 获取数据函数
* @param setter 设置数据函数
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param type 数据类型
* @param nullable 是否缓存null值
@@ -732,7 +732,7 @@ public class CachedManagerService implements CachedManager, Service {
protected CompletableFuture getSetAsync(
GetterFunc>> getter,
SetterAsyncFunc setter,
- String hash,
+ String schema,
String key,
Type type,
boolean nullable,
@@ -741,7 +741,7 @@ public class CachedManagerService implements CachedManager, Service {
checkEnable();
Objects.requireNonNull(supplier);
final Type cacheType = loadCacheType(type);
- final String id = idFor(hash, key);
+ final String id = idFor(schema, key);
CompletableFuture> sourceFuture = getter.get(id, expire, cacheType);
return sourceFuture.thenCompose(val -> {
if (CachedValue.isValid(val)) {
@@ -813,32 +813,32 @@ public class CachedManagerService implements CachedManager, Service {
}
}
- protected void setCache(CacheSource source, String hash, String key, Type type, T value, Duration expire) {
- setCache(source, idFor(hash, key), expire, loadCacheType(type, value), CachedValue.create(value));
+ protected void setCache(CacheSource source, String schema, String key, Type type, T value, Duration expire) {
+ setCache(source, idFor(schema, key), expire, loadCacheType(type, value), CachedValue.create(value));
}
protected CompletableFuture setCacheAsync(
- CacheSource source, String hash, String key, Type type, T value, Duration expire) {
- return setCacheAsync(source, idFor(hash, key), expire, loadCacheType(type, value), CachedValue.create(value));
+ CacheSource source, String schema, String key, Type type, T value, Duration expire) {
+ return setCacheAsync(source, idFor(schema, key), expire, loadCacheType(type, value), CachedValue.create(value));
}
- protected CachedValue bothGetCache(String hash, String key, Duration expire, Type type) {
- return bothGetCache(idFor(hash, key), expire, loadCacheType(type));
+ protected CachedValue bothGetCache(String schema, String key, Duration expire, Type type) {
+ return bothGetCache(idFor(schema, key), expire, loadCacheType(type));
}
/**
* 远程异步获取缓存数据, 过期返回null
*
* @param 泛型
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @param expire 过期时长,Duration.ZERO为永不过期
* @param type 数据类型
* @return 数据值
*/
protected CompletableFuture> bothGetCacheAsync(
- final String hash, final String key, Duration expire, final Type type) {
- return bothGetCacheAsync(idFor(hash, key), expire, loadCacheType(type));
+ final String schema, final String key, Duration expire, final Type type) {
+ return bothGetCacheAsync(idFor(schema, key), expire, loadCacheType(type));
}
protected CachedValue bothGetCache(final String id, final Duration expire, final Type cacheType) {
@@ -895,12 +895,12 @@ public class CachedManagerService implements CachedManager, Service {
/**
* 创建一个锁key
*
- * @param hash 缓存hash
+ * @param schema 缓存schema
* @param key 缓存键
* @return key
*/
- protected String idFor(String hash, String key) {
- return hash + ':' + key;
+ protected String idFor(String schema, String key) {
+ return schema + ':' + key;
}
/**
diff --git a/src/main/java/org/redkale/cached/spi/DynForCached.java b/src/main/java/org/redkale/cached/spi/DynForCached.java
index 88f70e123..b73a6d0c2 100644
--- a/src/main/java/org/redkale/cached/spi/DynForCached.java
+++ b/src/main/java/org/redkale/cached/spi/DynForCached.java
@@ -3,17 +3,16 @@
*/
package org.redkale.cached.spi;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import java.util.concurrent.TimeUnit;
import org.redkale.service.LoadMode;
/**
- * {@link org.redkale.cache.Cached}注解的动态扩展版,会多一个字段信息 用于识别方法是否已经动态处理过
+ * {@link org.redkale.cached.Cached}注解的动态扩展版,会多一个字段信息 用于识别方法是否已经动态处理过
*
* @author zhangjx
* @since 2.8.0
@@ -27,7 +26,7 @@ public @interface DynForCached {
String key();
- String hash();
+ String schema();
String localExpire();
diff --git a/src/test/java/org/redkale/test/cached/_DynLocalCacheInstance.java b/src/test/java/org/redkale/test/cached/_DynLocalCacheInstance.java
index 4d2676b23..d7767a918 100644
--- a/src/test/java/org/redkale/test/cached/_DynLocalCacheInstance.java
+++ b/src/test/java/org/redkale/test/cached/_DynLocalCacheInstance.java
@@ -12,11 +12,11 @@ import java.util.concurrent.TimeUnit;
import org.redkale.annotation.Resource;
import org.redkale.annotation.ResourceType;
import org.redkale.cached.spi.CachedAction;
+import org.redkale.cached.spi.DynForCached;
import org.redkale.net.sncp.Sncp.SncpDyn;
import org.redkale.util.AnyValue;
import org.redkale.util.RedkaleException;
import org.redkale.util.ThrowSupplier;
-import org.redkale.cached.spi.DynForCached;
@Resource(name = "")
@SncpDyn(remote = false, type = CachedInstance.class)
@@ -27,25 +27,25 @@ public class _DynLocalCacheInstance extends CachedInstance {
private String _redkale_mq;
- private CachedAction _redkale_getNameCacheAction1;
+ private CachedAction _redkale_getNameCachedAction1;
- private CachedAction _redkale_getInfoCacheAction2;
+ private CachedAction _redkale_getInfoCachedAction2;
- private CachedAction _redkale_getNameAsyncCacheAction3;
+ private CachedAction _redkale_getNameAsyncCachedAction3;
- private CachedAction _redkale_getInfo2AsyncCacheAction4;
+ private CachedAction _redkale_getInfo2AsyncCachedAction4;
- private CachedAction _redkale_getName2AsyncCacheAction5;
+ private CachedAction _redkale_getName2AsyncCachedAction5;
- private CachedAction _redkale_getInfoAsyncCacheAction6;
+ private CachedAction _redkale_getInfoAsyncCachedAction6;
- private CachedAction _redkale_getName2CacheAction7;
+ private CachedAction _redkale_getName2CachedAction7;
public _DynLocalCacheInstance() {}
@DynForCached(
- dynField = "_redkale_getNameCacheAction1",
- hash = "",
+ dynField = "_redkale_getNameCachedAction1",
+ schema = "",
key = "name",
nullable = false,
timeUnit = TimeUnit.SECONDS,
@@ -53,7 +53,7 @@ public class _DynLocalCacheInstance extends CachedInstance {
localExpire = "30")
public String getName() {
ThrowSupplier supplier = () -> this.getName_afterCache();
- return _redkale_getNameCacheAction1.get(supplier);
+ return _redkale_getNameCachedAction1.get(supplier);
}
private String getName_afterCache() {
@@ -61,8 +61,8 @@ public class _DynLocalCacheInstance extends CachedInstance {
}
@DynForCached(
- dynField = "_redkale_getInfoCacheAction2",
- hash = "",
+ dynField = "_redkale_getInfoCachedAction2",
+ schema = "",
key = "info_#{id}_file#{files.one}",
nullable = false,
timeUnit = TimeUnit.SECONDS,
@@ -70,7 +70,7 @@ public class _DynLocalCacheInstance extends CachedInstance {
localExpire = "30")
public File getInfo(CachedInstance.ParamBean bean, int id, List idList, Map files) {
ThrowSupplier supplier = () -> this.getInfo_afterCache(bean, id, idList, files);
- return _redkale_getInfoCacheAction2.get(supplier);
+ return _redkale_getInfoCachedAction2.get(supplier);
}
private File getInfo_afterCache(
@@ -79,8 +79,8 @@ public class _DynLocalCacheInstance extends CachedInstance {
}
@DynForCached(
- dynField = "_redkale_getNameAsyncCacheAction3",
- hash = "",
+ dynField = "_redkale_getNameAsyncCachedAction3",
+ schema = "",
key = "name",
nullable = false,
timeUnit = TimeUnit.SECONDS,
@@ -88,7 +88,7 @@ public class _DynLocalCacheInstance extends CachedInstance {
localExpire = "30")
public CompletableFuture getNameAsync() {
ThrowSupplier> supplier = () -> this.getNameAsync_afterCache();
- return _redkale_getNameAsyncCacheAction3.get(supplier);
+ return _redkale_getNameAsyncCachedAction3.get(supplier);
}
private CompletableFuture getNameAsync_afterCache() {
@@ -96,8 +96,8 @@ public class _DynLocalCacheInstance extends CachedInstance {
}
@DynForCached(
- dynField = "_redkale_getInfo2AsyncCacheAction4",
- hash = "",
+ dynField = "_redkale_getInfo2AsyncCachedAction4",
+ schema = "",
key = "info_#{id}_file#{files.one}",
nullable = false,
timeUnit = TimeUnit.SECONDS,
@@ -108,7 +108,7 @@ public class _DynLocalCacheInstance extends CachedInstance {
throws IOException, InstantiationException {
ThrowSupplier>> supplier =
() -> this.getInfo2Async_afterCache(bean, id, idList, files);
- return _redkale_getInfo2AsyncCacheAction4.get(supplier, bean, id, idList, files);
+ return _redkale_getInfo2AsyncCachedAction4.get(supplier, bean, id, idList, files);
}
private CompletableFuture