cached包重命名
This commit is contained in:
@@ -38,11 +38,11 @@
|
||||
  以参数code+map.id为key将结果进行远程缓存60毫秒
|
||||
```java
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
private CachedManager cachedManager;
|
||||
|
||||
//实时修改远程缓存的key值
|
||||
public void updateName(String code, Map<String, Long> map) {
|
||||
cacheManager.remoteSetString(code, code + "_" + map.get("id"), Duration.ofMillis(60));
|
||||
cachedManager.remoteSetString(code, code + "_" + map.get("id"), Duration.ofMillis(60));
|
||||
}
|
||||
|
||||
@Cached(key = "#{code}_#{map.id}", remoteExpire = "60", timeUnit = TimeUnit.MILLISECONDS)
|
||||
@@ -59,5 +59,5 @@
|
||||
remote: 远程CacheSource的资源名
|
||||
broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true
|
||||
-->
|
||||
<cache enabled="true" remote="xxx" broadcastable="true"/>
|
||||
<cached enabled="true" remote="xxx" broadcastable="true"/>
|
||||
```
|
||||
@@ -49,7 +49,7 @@ serviceid1_name1 serviceid1_name2 serviceid2_name1 serviceid2_name2
|
||||
remote: 远程CacheSource的资源名
|
||||
broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true
|
||||
-->
|
||||
<cache enabled="true" remote="xxx" broadcastable="true"/>
|
||||
<cached enabled="true" remote="xxx" broadcastable="true"/>
|
||||
|
||||
<!--
|
||||
【节点全局唯一】
|
||||
|
||||
@@ -13,8 +13,8 @@ module org.redkale {
|
||||
exports org.redkale.annotation;
|
||||
exports org.redkale.boot;
|
||||
exports org.redkale.boot.watch;
|
||||
exports org.redkale.cache;
|
||||
exports org.redkale.cache.spi;
|
||||
exports org.redkale.cached;
|
||||
exports org.redkale.cached.spi;
|
||||
exports org.redkale.cluster;
|
||||
exports org.redkale.cluster.spi;
|
||||
exports org.redkale.convert;
|
||||
@@ -24,8 +24,8 @@ module org.redkale {
|
||||
exports org.redkale.convert.proto;
|
||||
exports org.redkale.convert.spi;
|
||||
exports org.redkale.inject;
|
||||
exports org.redkale.lock;
|
||||
exports org.redkale.lock.spi;
|
||||
exports org.redkale.locked;
|
||||
exports org.redkale.locked.spi;
|
||||
exports org.redkale.mq;
|
||||
exports org.redkale.mq.spi;
|
||||
exports org.redkale.net;
|
||||
@@ -43,7 +43,7 @@ module org.redkale {
|
||||
exports org.redkale.watch;
|
||||
|
||||
uses org.redkale.props.spi.PropertiesAgentProvider;
|
||||
uses org.redkale.cache.spi.CacheManagerProvider;
|
||||
uses org.redkale.cached.spi.CachedManagerProvider;
|
||||
uses org.redkale.cluster.spi.ClusterAgentProvider;
|
||||
uses org.redkale.convert.spi.ConvertProvider;
|
||||
uses org.redkale.mq.spi.MessageAgentProvider;
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.logging.*;
|
||||
import org.redkale.annotation.Nonnull;
|
||||
import org.redkale.asm.AsmMethodBoost;
|
||||
import org.redkale.boot.ClassFilter.FilterEntry;
|
||||
import org.redkale.cache.spi.CacheModuleEngine;
|
||||
import org.redkale.cached.spi.CachedModuleEngine;
|
||||
import org.redkale.cluster.*;
|
||||
import org.redkale.cluster.spi.ClusterAgent;
|
||||
import org.redkale.cluster.spi.ClusterModuleEngine;
|
||||
@@ -35,7 +35,7 @@ import org.redkale.convert.proto.ProtobufFactory;
|
||||
import org.redkale.inject.ResourceEvent;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.inject.ResourceTypeLoader;
|
||||
import org.redkale.lock.spi.LockModuleEngine;
|
||||
import org.redkale.locked.spi.LockedModuleEngine;
|
||||
import org.redkale.mq.spi.MessageAgent;
|
||||
import org.redkale.mq.spi.MessageModuleEngine;
|
||||
import org.redkale.net.*;
|
||||
@@ -312,8 +312,8 @@ public final class Application {
|
||||
moduleEngines.add(new MessageModuleEngine(this));
|
||||
moduleEngines.add(new ClusterModuleEngine(this));
|
||||
moduleEngines.add(new ScheduleModuleEngine(this));
|
||||
moduleEngines.add(new CacheModuleEngine(this));
|
||||
moduleEngines.add(new LockModuleEngine(this));
|
||||
moduleEngines.add(new CachedModuleEngine(this));
|
||||
moduleEngines.add(new LockedModuleEngine(this));
|
||||
|
||||
// 根据本地日志配置文件初始化日志
|
||||
loggingModule.reconfigLogging(true, appConfig.locaLogProperties);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
|
||||
/**
|
||||
* 自定义的CacheManager加载器, 如果标记@Priority加载器的优先级需要大于1000, 1000以下预留给官方加载器
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface CacheManagerProvider extends InstanceProvider<CacheManager> {}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache;
|
||||
package org.redkale.cached;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
@@ -40,7 +40,7 @@ public @interface Cached {
|
||||
*
|
||||
* @return hash
|
||||
*/
|
||||
String hash() default CacheManager.DEFAULT_HASH;
|
||||
String hash() default CachedManager.DEFAULT_HASH;
|
||||
|
||||
/**
|
||||
* 本地缓存过期时长, 0表示永不过期, -1表示不作本地缓存。<br>
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache;
|
||||
package org.redkale.cached;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.Duration;
|
||||
@@ -16,10 +16,10 @@ import org.redkale.util.ThrowSupplier;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface CacheManager {
|
||||
public interface CachedManager {
|
||||
|
||||
/** 默认的hash */
|
||||
public static final String DEFAULT_HASH = "cache-hash";
|
||||
public static final String DEFAULT_HASH = "cached-hash";
|
||||
|
||||
// -------------------------------------- 本地缓存 --------------------------------------
|
||||
/**
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@@ -12,7 +12,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import org.redkale.annotation.ClassDepends;
|
||||
import org.redkale.annotation.Nullable;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.util.Environment;
|
||||
@@ -29,15 +29,15 @@ import org.redkale.util.TypeToken;
|
||||
* @since 2.8.0
|
||||
*/
|
||||
@ClassDepends
|
||||
public class CacheAction {
|
||||
public class CachedAction {
|
||||
|
||||
@Resource
|
||||
private Environment environment;
|
||||
|
||||
@Resource
|
||||
private CacheManager manager;
|
||||
private CachedManager manager;
|
||||
|
||||
private final CacheEntry cached;
|
||||
private final CachedEntry cached;
|
||||
|
||||
private final Method method;
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CacheAction {
|
||||
String templetKey;
|
||||
|
||||
// 缓存key生成器
|
||||
private CacheKeyGenerator keyGenerator;
|
||||
private CachedKeyGenerator keyGenerator;
|
||||
|
||||
// 父对象
|
||||
private Object service;
|
||||
@@ -81,7 +81,7 @@ public class CacheAction {
|
||||
// 远程缓存过期时长,Duration.ZERO为永不过期,为null表示不远程缓存
|
||||
private Duration remoteExpire;
|
||||
|
||||
CacheAction(CacheEntry cached, Method method, Class serviceClass, String[] paramNames, String fieldName) {
|
||||
CachedAction(CachedEntry cached, Method method, Class serviceClass, String[] paramNames, String fieldName) {
|
||||
this.cached = cached;
|
||||
this.method = method;
|
||||
this.nullable = cached.isNullable();
|
||||
@@ -96,17 +96,17 @@ public class CacheAction {
|
||||
}
|
||||
|
||||
void init(ResourceFactory resourceFactory, Object service) {
|
||||
this.hash = cached.getHash().trim().isEmpty() || CacheManager.DEFAULT_HASH.equals(cached.getHash())
|
||||
? CacheManager.DEFAULT_HASH
|
||||
this.hash = cached.getHash().trim().isEmpty() || CachedManager.DEFAULT_HASH.equals(cached.getHash())
|
||||
? CachedManager.DEFAULT_HASH
|
||||
: environment.getPropertyValue(cached.getHash());
|
||||
String key = environment.getPropertyValue(cached.getKey());
|
||||
this.templetKey = key;
|
||||
if (key.startsWith("@")) { // 动态加载缓存key生成器
|
||||
String generatorName = key.substring(1);
|
||||
this.keyGenerator = resourceFactory.findChild(generatorName, CacheKeyGenerator.class);
|
||||
this.keyGenerator = resourceFactory.findChild(generatorName, CachedKeyGenerator.class);
|
||||
} else {
|
||||
MultiHashKey dynKey = MultiHashKey.create(paramNames, key);
|
||||
this.keyGenerator = CacheKeyGenerator.create(dynKey);
|
||||
this.keyGenerator = CachedKeyGenerator.create(dynKey);
|
||||
}
|
||||
this.localExpire = createDuration(cached.getLocalExpire());
|
||||
this.remoteExpire = createDuration(cached.getRemoteExpire());
|
||||
@@ -160,7 +160,7 @@ public class CacheAction {
|
||||
}
|
||||
}
|
||||
|
||||
public CacheEntry getCached() {
|
||||
public CachedEntry getCached() {
|
||||
return cached;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -25,7 +25,7 @@ import org.redkale.asm.MethodVisitor;
|
||||
import org.redkale.asm.Opcodes;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
import org.redkale.asm.Type;
|
||||
import org.redkale.cache.Cached;
|
||||
import org.redkale.cached.Cached;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.service.LoadMode;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
@@ -40,17 +40,17 @@ import org.redkale.util.TypeToken;
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
public class CachedAsmMethodBoost extends AsmMethodBoost {
|
||||
|
||||
private static final java.lang.reflect.Type FUTURE_VOID = new TypeToken<CompletableFuture<Void>>() {}.getType();
|
||||
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class, DynForCache.class);
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class, DynForCached.class);
|
||||
|
||||
private final Logger logger = Logger.getLogger(getClass().getSimpleName());
|
||||
|
||||
private Map<String, CacheAction> actionMap;
|
||||
private Map<String, CachedAction> actionMap;
|
||||
|
||||
public CacheAsmMethodBoost(boolean remote, Class serviceType) {
|
||||
public CachedAsmMethodBoost(boolean remote, Class serviceType) {
|
||||
super(remote, serviceType);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
final List filterAnns,
|
||||
final Method method,
|
||||
final String newMethodName) {
|
||||
Map<String, CacheAction> actions = this.actionMap;
|
||||
Map<String, CachedAction> actions = this.actionMap;
|
||||
if (actions == null) {
|
||||
actions = new LinkedHashMap<>();
|
||||
this.actionMap = actions;
|
||||
@@ -80,7 +80,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
if (!LoadMode.matches(remote, cached.mode())) {
|
||||
return newMethodName;
|
||||
}
|
||||
if (method.getAnnotation(DynForCache.class) != null) {
|
||||
if (method.getAnnotation(DynForCached.class) != null) {
|
||||
return newMethodName;
|
||||
}
|
||||
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
|
||||
@@ -95,11 +95,12 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on void method, but on " + method);
|
||||
}
|
||||
final int actionIndex = fieldIndex.incrementAndGet();
|
||||
final String rsMethodName = method.getName() + "_afterCache";
|
||||
final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + actionIndex;
|
||||
final String rsMethodName = method.getName() + "_afterCached";
|
||||
final String dynFieldName =
|
||||
fieldPrefix + "_" + method.getName() + CachedAction.class.getSimpleName() + actionIndex;
|
||||
final AsmMethodBean methodBean = getMethodBean(method);
|
||||
{ // 定义一个新方法调用 this.rsMethodName
|
||||
final String cacheDynDesc = Type.getDescriptor(DynForCache.class);
|
||||
final String cacheDynDesc = Type.getDescriptor(DynForCached.class);
|
||||
final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean);
|
||||
// mv.setDebug(true);
|
||||
AnnotationVisitor av = mv.visitAnnotation(cacheDynDesc, true);
|
||||
@@ -123,7 +124,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
Label l1 = new Label();
|
||||
mv.visitLabel(l1);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, dynFieldName, Type.getDescriptor(CacheAction.class));
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, dynFieldName, Type.getDescriptor(CachedAction.class));
|
||||
|
||||
mv.visitVarInsn(ALOAD, 1 + method.getParameterCount());
|
||||
Asms.visitInsn(mv, method.getParameterCount());
|
||||
@@ -160,7 +161,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
String throwFuncDesc = Type.getDescriptor(ThrowSupplier.class);
|
||||
mv.visitMethodInsn(
|
||||
INVOKEVIRTUAL,
|
||||
CacheAction.class.getName().replace('.', '/'),
|
||||
CachedAction.class.getName().replace('.', '/'),
|
||||
"get",
|
||||
"(" + throwFuncDesc + "[Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
false);
|
||||
@@ -174,8 +175,8 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
|
||||
mv.visitMaxs(20, 20);
|
||||
mv.visitEnd();
|
||||
CacheAction action = new CacheAction(
|
||||
new CacheEntry(cached), method, serviceType, methodBean.paramNameArray(method), dynFieldName);
|
||||
CachedAction action = new CachedAction(
|
||||
new CachedEntry(cached), method, serviceType, methodBean.paramNameArray(method), dynFieldName);
|
||||
actions.put(dynFieldName, action);
|
||||
}
|
||||
{ // ThrowSupplier
|
||||
@@ -198,7 +199,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
}
|
||||
{ // 定义字段
|
||||
FieldVisitor fv =
|
||||
cw.visitField(ACC_PRIVATE, dynFieldName, Type.getDescriptor(CacheAction.class), null, null);
|
||||
cw.visitField(ACC_PRIVATE, dynFieldName, Type.getDescriptor(CachedAction.class), null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
if (actions.size() == 1) {
|
||||
@@ -218,12 +219,12 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
actionMap = new LinkedHashMap<>();
|
||||
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(clazz);
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
DynForCache cached = method.getAnnotation(DynForCache.class);
|
||||
DynForCached cached = method.getAnnotation(DynForCached.class);
|
||||
if (cached != null) {
|
||||
String dynFieldName = cached.dynField();
|
||||
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
|
||||
CacheAction action = new CacheAction(
|
||||
new CacheEntry(cached),
|
||||
CachedAction action = new CachedAction(
|
||||
new CachedEntry(cached),
|
||||
method,
|
||||
serviceType,
|
||||
methodBean.paramNameArray(method),
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redkale.cache.Cached;
|
||||
import org.redkale.cached.Cached;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ import org.redkale.convert.json.JsonConvert;
|
||||
* @since 2.8.0
|
||||
*
|
||||
*/
|
||||
public class CacheEntry {
|
||||
public class CachedEntry {
|
||||
|
||||
private String key;
|
||||
|
||||
@@ -30,9 +30,9 @@ public class CacheEntry {
|
||||
|
||||
private boolean nullable;
|
||||
|
||||
public CacheEntry() {}
|
||||
public CachedEntry() {}
|
||||
|
||||
public CacheEntry(DynForCache cached) {
|
||||
public CachedEntry(DynForCached cached) {
|
||||
this.key = cached.key();
|
||||
this.hash = cached.hash();
|
||||
this.localExpire = cached.localExpire();
|
||||
@@ -41,7 +41,7 @@ public class CacheEntry {
|
||||
this.nullable = cached.nullable();
|
||||
}
|
||||
|
||||
public CacheEntry(Cached cached) {
|
||||
public CachedEntry(Cached cached) {
|
||||
this.key = cached.key();
|
||||
this.hash = cached.hash();
|
||||
this.localExpire = cached.localExpire();
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
*/
|
||||
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.redkale.util.MultiHashKey;
|
||||
@@ -17,7 +17,7 @@ import org.redkale.util.MultiHashKey;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface CacheKeyGenerator {
|
||||
public interface CachedKeyGenerator {
|
||||
|
||||
/**
|
||||
* 根据service和方法名生成key
|
||||
@@ -27,7 +27,7 @@ public interface CacheKeyGenerator {
|
||||
* @param params 参数值
|
||||
* @return key值
|
||||
*/
|
||||
public String generate(Object target, CacheAction action, Object... params);
|
||||
public String generate(Object target, CachedAction action, Object... params);
|
||||
|
||||
/**
|
||||
* 生成器的名字
|
||||
@@ -41,13 +41,13 @@ public interface CacheKeyGenerator {
|
||||
/**
|
||||
* 根据MultiHashKey生成一个CacheKeyGenerator
|
||||
* @param key MultiHashKey 不能为空
|
||||
* @return CacheKeyGenerator
|
||||
* @return CachedKeyGenerator
|
||||
*/
|
||||
public static CacheKeyGenerator create(MultiHashKey key) {
|
||||
public static CachedKeyGenerator create(MultiHashKey key) {
|
||||
Objects.requireNonNull(key);
|
||||
return new CacheKeyGenerator() {
|
||||
return new CachedKeyGenerator() {
|
||||
@Override
|
||||
public String generate(Object target, CacheAction action, Object... params) {
|
||||
public String generate(Object target, CachedAction action, Object... params) {
|
||||
return key.keyFor(params);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
|
||||
/**
|
||||
* 自定义的CachedManager加载器, 如果标记@Priority加载器的优先级需要大于1000, 1000以下预留给官方加载器
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface CachedManagerProvider extends InstanceProvider<CachedManager> {}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -21,7 +21,7 @@ import org.redkale.annotation.Nullable;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.service.Local;
|
||||
import org.redkale.service.Service;
|
||||
@@ -44,8 +44,8 @@ import org.redkale.util.TypeToken;
|
||||
@Local
|
||||
@Component
|
||||
@AutoLoad(false)
|
||||
@ResourceType(CacheManager.class)
|
||||
public class CacheManagerService implements CacheManager, Service {
|
||||
@ResourceType(CachedManager.class)
|
||||
public class CachedManagerService implements CachedManager, Service {
|
||||
|
||||
public static final String CACHE_CHANNEL_TOPIC = "cache-update-channel";
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
protected final ConcurrentSkipListSet<String> hashNames = new ConcurrentSkipListSet<>();
|
||||
|
||||
// 缓存无效时使用的同步锁
|
||||
private final ConcurrentHashMap<String, CacheValue> syncLock = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, CachedValue> syncLock = new ConcurrentHashMap<>();
|
||||
|
||||
// 缓存无效时使用的异步锁
|
||||
private final ConcurrentHashMap<String, CacheAsyncEntry> asyncLock = new ConcurrentHashMap<>();
|
||||
@@ -81,20 +81,20 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
|
||||
protected CacheEventListener remoteListener;
|
||||
|
||||
protected CacheManagerService(@Nullable CacheSource remoteSource) {
|
||||
protected CachedManagerService(@Nullable CacheSource remoteSource) {
|
||||
this.remoteSource = remoteSource;
|
||||
}
|
||||
|
||||
// 一般用于独立组件
|
||||
public static CacheManagerService create(@Nullable CacheSource remoteSource) {
|
||||
return new CacheManagerService(remoteSource);
|
||||
public static CachedManagerService create(@Nullable CacheSource remoteSource) {
|
||||
return new CachedManagerService(remoteSource);
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public CacheManagerService enabled(boolean val) {
|
||||
public CachedManagerService enabled(boolean val) {
|
||||
this.enabled = val;
|
||||
return this;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public CacheManagerService addHash(String hash) {
|
||||
public CachedManagerService addHash(String hash) {
|
||||
this.hashNames.add(hash);
|
||||
return this;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
@Override
|
||||
public <T> T localGet(final String hash, final String key, final Type type) {
|
||||
checkEnable();
|
||||
return CacheValue.get(localSource.get(idFor(hash, key), loadCacheType(type)));
|
||||
return CachedValue.get(localSource.get(idFor(hash, key), loadCacheType(type)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +278,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
@Override
|
||||
public <T> T remoteGet(final String hash, final String key, final Type type) {
|
||||
checkEnable();
|
||||
return CacheValue.get(remoteSource.get(idFor(hash, key), loadCacheType(type)));
|
||||
return CachedValue.get(remoteSource.get(idFor(hash, key), loadCacheType(type)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,8 +293,8 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
@Override
|
||||
public <T> CompletableFuture<T> remoteGetAsync(final String hash, final String key, final Type type) {
|
||||
checkEnable();
|
||||
CompletableFuture<CacheValue<T>> future = remoteSource.getAsync(idFor(hash, key), loadCacheType(type));
|
||||
return future.thenApply(CacheValue::get);
|
||||
CompletableFuture<CachedValue<T>> future = remoteSource.getAsync(idFor(hash, key), loadCacheType(type));
|
||||
return future.thenApply(CachedValue::get);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,7 +427,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
*/
|
||||
@Override
|
||||
public <T> T bothGet(final String hash, final String key, final Type type) {
|
||||
return CacheValue.get(bothGetCache(hash, key, (Duration) null, type));
|
||||
return CachedValue.get(bothGetCache(hash, key, (Duration) null, type));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,7 +441,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
*/
|
||||
@Override
|
||||
public <T> CompletableFuture<T> bothGetAsync(final String hash, final String key, final Type type) {
|
||||
return bothGetCacheAsync(hash, key, (Duration) null, type).thenApply(CacheValue::get);
|
||||
return bothGetCacheAsync(hash, key, (Duration) null, type).thenApply(CachedValue::get);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -678,7 +678,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @return 数据值
|
||||
*/
|
||||
protected <T> T getSet(
|
||||
GetterFunc<CacheValue<T>> getter,
|
||||
GetterFunc<CachedValue<T>> getter,
|
||||
SetterSyncFunc setter,
|
||||
String hash,
|
||||
String key,
|
||||
@@ -691,16 +691,16 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
Objects.requireNonNull(supplier);
|
||||
final Type cacheType = loadCacheType(type);
|
||||
final String id = idFor(hash, key);
|
||||
CacheValue<T> cacheVal = getter.get(id, expire, cacheType);
|
||||
if (CacheValue.isValid(cacheVal)) {
|
||||
CachedValue<T> cacheVal = getter.get(id, expire, cacheType);
|
||||
if (CachedValue.isValid(cacheVal)) {
|
||||
return cacheVal.getVal();
|
||||
}
|
||||
Function<String, CacheValue> func = k -> {
|
||||
CacheValue<T> oldCacheVal = getter.get(id, expire, cacheType);
|
||||
if (CacheValue.isValid(oldCacheVal)) {
|
||||
Function<String, CachedValue> func = k -> {
|
||||
CachedValue<T> oldCacheVal = getter.get(id, expire, cacheType);
|
||||
if (CachedValue.isValid(oldCacheVal)) {
|
||||
return oldCacheVal;
|
||||
}
|
||||
CacheValue<T> newCacheVal;
|
||||
CachedValue<T> newCacheVal;
|
||||
try {
|
||||
newCacheVal = toCacheSupplier(nullable, supplier).get();
|
||||
} catch (RuntimeException e) {
|
||||
@@ -708,14 +708,14 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
} catch (Throwable t) {
|
||||
throw new RedkaleException(t);
|
||||
}
|
||||
if (CacheValue.isValid(newCacheVal)) {
|
||||
if (CachedValue.isValid(newCacheVal)) {
|
||||
setter.set(id, expire, cacheType, newCacheVal);
|
||||
}
|
||||
return newCacheVal;
|
||||
};
|
||||
cacheVal = syncLock.computeIfAbsent(id, func);
|
||||
try {
|
||||
return CacheValue.get(cacheVal);
|
||||
return CachedValue.get(cacheVal);
|
||||
} finally {
|
||||
syncLock.remove(id);
|
||||
}
|
||||
@@ -736,7 +736,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @return 数据值
|
||||
*/
|
||||
protected <T> CompletableFuture<T> getSetAsync(
|
||||
GetterFunc<CompletableFuture<CacheValue<T>>> getter,
|
||||
GetterFunc<CompletableFuture<CachedValue<T>>> getter,
|
||||
SetterAsyncFunc setter,
|
||||
String hash,
|
||||
String key,
|
||||
@@ -748,9 +748,9 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
Objects.requireNonNull(supplier);
|
||||
final Type cacheType = loadCacheType(type);
|
||||
final String id = idFor(hash, key);
|
||||
CompletableFuture<CacheValue<T>> sourceFuture = getter.get(id, expire, cacheType);
|
||||
CompletableFuture<CachedValue<T>> sourceFuture = getter.get(id, expire, cacheType);
|
||||
return sourceFuture.thenCompose(val -> {
|
||||
if (CacheValue.isValid(val)) {
|
||||
if (CachedValue.isValid(val)) {
|
||||
return CompletableFuture.completedFuture(val.getVal());
|
||||
}
|
||||
final CacheAsyncEntry entry = asyncLock.computeIfAbsent(id, CacheAsyncEntry::new);
|
||||
@@ -761,12 +761,12 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
if (e != null) {
|
||||
entry.fail(e);
|
||||
}
|
||||
CacheValue<T> cacheVal = toCacheValue(nullable, v);
|
||||
if (CacheValue.isValid(cacheVal)) {
|
||||
CachedValue<T> cacheVal = toCacheValue(nullable, v);
|
||||
if (CachedValue.isValid(cacheVal)) {
|
||||
setter.set(id, expire, cacheType, cacheVal)
|
||||
.whenComplete((v2, e2) -> entry.success(CacheValue.get(cacheVal)));
|
||||
.whenComplete((v2, e2) -> entry.success(CachedValue.get(cacheVal)));
|
||||
} else {
|
||||
entry.success(CacheValue.get(cacheVal));
|
||||
entry.success(CachedValue.get(cacheVal));
|
||||
}
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
@@ -778,25 +778,25 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
}
|
||||
|
||||
protected <T> CompletableFuture<Void> localSetCacheAsync(
|
||||
String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
return setCacheAsync(localSource, id, expire, cacheType, cacheVal);
|
||||
}
|
||||
|
||||
protected <T> CompletableFuture<Void> remoteSetCacheAsync(
|
||||
String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
return setCacheAsync(remoteSource, id, expire, cacheType, cacheVal);
|
||||
}
|
||||
|
||||
protected <T> void localSetCache(String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
protected <T> void localSetCache(String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
setCache(localSource, id, expire, cacheType, cacheVal);
|
||||
}
|
||||
|
||||
protected <T> void remoteSetCache(String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
protected <T> void remoteSetCache(String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
setCache(remoteSource, id, expire, cacheType, cacheVal);
|
||||
}
|
||||
|
||||
protected <T> void setCache(
|
||||
CacheSource source, String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
CacheSource source, String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
checkEnable();
|
||||
Objects.requireNonNull(expire);
|
||||
long millis = expire.toMillis();
|
||||
@@ -808,7 +808,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
}
|
||||
|
||||
protected <T> CompletableFuture<Void> setCacheAsync(
|
||||
CacheSource source, String id, Duration expire, Type cacheType, CacheValue<T> cacheVal) {
|
||||
CacheSource source, String id, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
|
||||
checkEnable();
|
||||
Objects.requireNonNull(expire);
|
||||
long millis = expire.toMillis();
|
||||
@@ -820,15 +820,15 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
}
|
||||
|
||||
protected <T> void setCache(CacheSource source, String hash, String key, Type type, T value, Duration expire) {
|
||||
setCache(source, idFor(hash, key), expire, loadCacheType(type, value), CacheValue.create(value));
|
||||
setCache(source, idFor(hash, key), expire, loadCacheType(type, value), CachedValue.create(value));
|
||||
}
|
||||
|
||||
protected <T> CompletableFuture<Void> setCacheAsync(
|
||||
CacheSource source, String hash, String key, Type type, T value, Duration expire) {
|
||||
return setCacheAsync(source, idFor(hash, key), expire, loadCacheType(type, value), CacheValue.create(value));
|
||||
return setCacheAsync(source, idFor(hash, key), expire, loadCacheType(type, value), CachedValue.create(value));
|
||||
}
|
||||
|
||||
protected <T> CacheValue<T> bothGetCache(String hash, String key, Duration expire, Type type) {
|
||||
protected <T> CachedValue<T> bothGetCache(String hash, String key, Duration expire, Type type) {
|
||||
return bothGetCache(idFor(hash, key), expire, loadCacheType(type));
|
||||
}
|
||||
|
||||
@@ -842,20 +842,20 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @param type 数据类型
|
||||
* @return 数据值
|
||||
*/
|
||||
protected <T> CompletableFuture<CacheValue<T>> bothGetCacheAsync(
|
||||
protected <T> CompletableFuture<CachedValue<T>> bothGetCacheAsync(
|
||||
final String hash, final String key, Duration expire, final Type type) {
|
||||
return bothGetCacheAsync(idFor(hash, key), expire, loadCacheType(type));
|
||||
}
|
||||
|
||||
protected <T> CacheValue<T> bothGetCache(final String id, final Duration expire, final Type cacheType) {
|
||||
protected <T> CachedValue<T> bothGetCache(final String id, final Duration expire, final Type cacheType) {
|
||||
checkEnable();
|
||||
CacheValue<T> cacheVal = localSource.get(id, cacheType);
|
||||
if (CacheValue.isValid(cacheVal)) {
|
||||
CachedValue<T> cacheVal = localSource.get(id, cacheType);
|
||||
if (CachedValue.isValid(cacheVal)) {
|
||||
return cacheVal;
|
||||
}
|
||||
if (remoteSource != null) {
|
||||
cacheVal = remoteSource.get(id, cacheType);
|
||||
if (CacheValue.isValid(cacheVal) && expire != null) {
|
||||
if (CachedValue.isValid(cacheVal) && expire != null) {
|
||||
setCache(localSource, id, expire, cacheType, cacheVal);
|
||||
}
|
||||
return cacheVal;
|
||||
@@ -873,16 +873,16 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @param cacheType 数据类型
|
||||
* @return 数据值
|
||||
*/
|
||||
protected <T> CompletableFuture<CacheValue<T>> bothGetCacheAsync(String id, Duration expire, Type cacheType) {
|
||||
protected <T> CompletableFuture<CachedValue<T>> bothGetCacheAsync(String id, Duration expire, Type cacheType) {
|
||||
checkEnable();
|
||||
CacheValue<T> val = localSource.get(id, cacheType); // 内存操作,无需异步
|
||||
if (CacheValue.isValid(val)) {
|
||||
CachedValue<T> val = localSource.get(id, cacheType); // 内存操作,无需异步
|
||||
if (CachedValue.isValid(val)) {
|
||||
return CompletableFuture.completedFuture(val);
|
||||
}
|
||||
if (remoteSource != null) {
|
||||
CompletableFuture<CacheValue<T>> future = remoteSource.getAsync(id, cacheType);
|
||||
CompletableFuture<CachedValue<T>> future = remoteSource.getAsync(id, cacheType);
|
||||
return future.thenApply(v -> {
|
||||
if (CacheValue.isValid(v) && expire != null) {
|
||||
if (CachedValue.isValid(v) && expire != null) {
|
||||
setCache(localSource, id, expire, cacheType, v);
|
||||
}
|
||||
return v;
|
||||
@@ -894,7 +894,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
|
||||
protected void checkEnable() {
|
||||
if (!enabled) {
|
||||
throw new RedkaleException(CacheManager.class.getSimpleName() + " is disabled");
|
||||
throw new RedkaleException(CachedManager.class.getSimpleName() + " is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -917,11 +917,11 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @param value 缓存值
|
||||
* @return CacheValue函数
|
||||
*/
|
||||
protected <T> CacheValue<T> toCacheValue(boolean nullable, T value) {
|
||||
protected <T> CachedValue<T> toCacheValue(boolean nullable, T value) {
|
||||
if (value == null) {
|
||||
return nullable ? CacheValue.create(value) : null;
|
||||
return nullable ? CachedValue.create(value) : null;
|
||||
}
|
||||
return CacheValue.create(value);
|
||||
return CachedValue.create(value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -932,7 +932,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
* @param supplier 数据函数
|
||||
* @return CacheValue函数
|
||||
*/
|
||||
protected <T> ThrowSupplier<CacheValue<T>> toCacheSupplier(boolean nullable, ThrowSupplier<T> supplier) {
|
||||
protected <T> ThrowSupplier<CachedValue<T>> toCacheSupplier(boolean nullable, ThrowSupplier<T> supplier) {
|
||||
return () -> toCacheValue(nullable, supplier.get());
|
||||
}
|
||||
|
||||
@@ -955,7 +955,7 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
*/
|
||||
protected Type loadCacheType(Type type) {
|
||||
return cacheValueTypes.computeIfAbsent(
|
||||
type, t -> TypeToken.createParameterizedType(null, CacheValue.class, type));
|
||||
type, t -> TypeToken.createParameterizedType(null, CachedValue.class, type));
|
||||
}
|
||||
|
||||
private static final Object NIL = new Object();
|
||||
@@ -967,12 +967,12 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
|
||||
protected static interface SetterSyncFunc {
|
||||
|
||||
public void set(String id, Duration expire, Type cacheType, CacheValue cacheVal);
|
||||
public void set(String id, Duration expire, Type cacheType, CachedValue cacheVal);
|
||||
}
|
||||
|
||||
protected static interface SetterAsyncFunc {
|
||||
|
||||
public CompletableFuture<Void> set(String id, Duration expire, Type cacheType, CacheValue cacheVal);
|
||||
public CompletableFuture<Void> set(String id, Duration expire, Type cacheType, CachedValue cacheVal);
|
||||
}
|
||||
|
||||
protected class CacheAsyncEntry {
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
@@ -15,7 +15,7 @@ import java.util.logging.Level;
|
||||
import org.redkale.asm.AsmMethodBoost;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.inject.ResourceTypeLoader;
|
||||
import org.redkale.service.Service;
|
||||
@@ -32,14 +32,14 @@ import org.redkale.util.RedkaleException;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class CacheModuleEngine extends ModuleEngine {
|
||||
public class CachedModuleEngine extends ModuleEngine {
|
||||
|
||||
// 全局缓存管理器
|
||||
private CacheManager cacheManager;
|
||||
private CachedManager cacheManager;
|
||||
|
||||
private AnyValue config;
|
||||
|
||||
public CacheModuleEngine(Application application) {
|
||||
public CachedModuleEngine(Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
*/
|
||||
@Override
|
||||
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||
return new CacheAsmMethodBoost(remote, serviceClass);
|
||||
return new CachedAsmMethodBoost(remote, serviceClass);
|
||||
}
|
||||
|
||||
/** 结束Application.init方法前被调用 */
|
||||
@@ -84,8 +84,8 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
((Service) this.cacheManager).init(this.config);
|
||||
}
|
||||
}
|
||||
this.resourceFactory.register("", CacheManager.class, this.cacheManager);
|
||||
ConcurrentHashMap<String, CacheKeyGenerator> generatorMap = new ConcurrentHashMap<>();
|
||||
this.resourceFactory.register("", CachedManager.class, this.cacheManager);
|
||||
ConcurrentHashMap<String, CachedKeyGenerator> generatorMap = new ConcurrentHashMap<>();
|
||||
this.resourceFactory.register(new ResourceTypeLoader() {
|
||||
|
||||
@Override
|
||||
@@ -97,13 +97,13 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
Field field,
|
||||
Object attachment) {
|
||||
try {
|
||||
CacheKeyGenerator generator = rf.find(resourceName, CacheKeyGenerator.class);
|
||||
CachedKeyGenerator generator = rf.find(resourceName, CachedKeyGenerator.class);
|
||||
if (generator == null) {
|
||||
return generator;
|
||||
}
|
||||
generator = generatorMap.computeIfAbsent(resourceName, n -> {
|
||||
for (CacheKeyGenerator instance :
|
||||
ServiceLoader.load(CacheKeyGenerator.class, application.getClassLoader())) {
|
||||
for (CachedKeyGenerator instance :
|
||||
ServiceLoader.load(CachedKeyGenerator.class, application.getClassLoader())) {
|
||||
if (Objects.equals(n, instance.name())) {
|
||||
rf.inject(instance);
|
||||
if (instance instanceof Service) {
|
||||
@@ -115,18 +115,18 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
return null;
|
||||
});
|
||||
if (generator != null) {
|
||||
rf.register(resourceName, CacheKeyGenerator.class, generator);
|
||||
rf.register(resourceName, CachedKeyGenerator.class, generator);
|
||||
}
|
||||
return generator;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, CacheKeyGenerator.class.getSimpleName() + " inject error", e);
|
||||
logger.log(Level.SEVERE, CachedKeyGenerator.class.getSimpleName() + " inject error", e);
|
||||
throw e instanceof RuntimeException ? (RuntimeException) e : new RedkaleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type resourceType() {
|
||||
return CacheKeyGenerator.class;
|
||||
return CachedKeyGenerator.class;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -141,22 +141,23 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
}
|
||||
}
|
||||
|
||||
private CacheManager createManager(AnyValue conf) {
|
||||
Iterator<CacheManagerProvider> it = ServiceLoader.load(CacheManagerProvider.class, application.getClassLoader())
|
||||
private CachedManager createManager(AnyValue conf) {
|
||||
Iterator<CachedManagerProvider> it = ServiceLoader.load(
|
||||
CachedManagerProvider.class, application.getClassLoader())
|
||||
.iterator();
|
||||
RedkaleClassLoader.putServiceLoader(CacheManagerProvider.class);
|
||||
List<CacheManagerProvider> providers = new ArrayList<>();
|
||||
RedkaleClassLoader.putServiceLoader(CachedManagerProvider.class);
|
||||
List<CachedManagerProvider> providers = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
CacheManagerProvider provider = it.next();
|
||||
CachedManagerProvider provider = it.next();
|
||||
if (provider != null && provider.acceptsConf(conf)) {
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(
|
||||
provider.getClass(), provider.getClass().getName());
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
for (CacheManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
for (CachedManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
return provider.createInstance();
|
||||
}
|
||||
return CacheManagerService.create(null).enabled(false);
|
||||
return CachedManagerService.create(null).enabled(false);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
@@ -15,26 +15,26 @@ import org.redkale.convert.json.JsonConvert;
|
||||
* @param <T> 泛型
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class CacheValue<T> {
|
||||
public class CachedValue<T> {
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
private T val;
|
||||
|
||||
public CacheValue() {}
|
||||
public CachedValue() {}
|
||||
|
||||
protected CacheValue(T value) {
|
||||
protected CachedValue(T value) {
|
||||
this.val = value;
|
||||
}
|
||||
|
||||
public static <T> CacheValue<T> create(T value) {
|
||||
return new CacheValue(value);
|
||||
public static <T> CachedValue<T> create(T value) {
|
||||
return new CachedValue(value);
|
||||
}
|
||||
|
||||
public static boolean isValid(CacheValue val) {
|
||||
public static boolean isValid(CachedValue val) {
|
||||
return val != null;
|
||||
}
|
||||
|
||||
public static <T> T get(CacheValue val) {
|
||||
public static <T> T get(CachedValue val) {
|
||||
return isValid(val) ? (T) val.getVal() : null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
package org.redkale.cached.spi;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@@ -21,7 +21,7 @@ import org.redkale.service.LoadMode;
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface DynForCache {
|
||||
public @interface DynForCached {
|
||||
|
||||
String dynField();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock;
|
||||
package org.redkale.locked;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock;
|
||||
package org.redkale.locked;
|
||||
|
||||
/**
|
||||
* //TODO 待实现
|
||||
@@ -13,4 +13,4 @@ package org.redkale.lock;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface LockManager {}
|
||||
public interface LockedManager {}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock.spi;
|
||||
package org.redkale.locked.spi;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@@ -20,7 +20,7 @@ import org.redkale.service.LoadMode;
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface DynForLock {
|
||||
public @interface DynForLocked {
|
||||
|
||||
String dynField();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock.spi;
|
||||
package org.redkale.locked.spi;
|
||||
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
|
||||
@@ -18,16 +18,16 @@ import org.redkale.asm.Label;
|
||||
import org.redkale.asm.MethodVisitor;
|
||||
import org.redkale.asm.Type;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.lock.Locked;
|
||||
import org.redkale.locked.Locked;
|
||||
import org.redkale.service.LoadMode;
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class LockAsmMethodBoost extends AsmMethodBoost {
|
||||
public class LockedAsmMethodBoost extends AsmMethodBoost {
|
||||
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class, DynForLock.class);
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class, DynForLocked.class);
|
||||
|
||||
public LockAsmMethodBoost(boolean remote, Class serviceType) {
|
||||
public LockedAsmMethodBoost(boolean remote, Class serviceType) {
|
||||
super(remote, serviceType);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LockAsmMethodBoost extends AsmMethodBoost {
|
||||
if (!LoadMode.matches(remote, locked.mode())) {
|
||||
return newMethodName;
|
||||
}
|
||||
if (method.getAnnotation(DynForLock.class) != null) {
|
||||
if (method.getAnnotation(DynForLocked.class) != null) {
|
||||
return newMethodName;
|
||||
}
|
||||
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
|
||||
@@ -68,7 +68,7 @@ public class LockAsmMethodBoost extends AsmMethodBoost {
|
||||
final String dynFieldName = fieldPrefix + "_" + method.getName() + "LockAction" + fieldIndex.incrementAndGet();
|
||||
{ // 定义一个新方法调用 this.rsMethodName
|
||||
final AsmMethodBean methodBean = getMethodBean(method);
|
||||
final String lockDynDesc = Type.getDescriptor(DynForLock.class);
|
||||
final String lockDynDesc = Type.getDescriptor(DynForLocked.class);
|
||||
final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean);
|
||||
// mv.setDebug(true);
|
||||
Label l0 = new Label();
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
*/
|
||||
|
||||
package org.redkale.lock.spi;
|
||||
package org.redkale.locked.spi;
|
||||
|
||||
import org.redkale.lock.LockManager;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
import org.redkale.locked.LockedManager;
|
||||
|
||||
/**
|
||||
* 自定义的LockManager加载器, 如果标记@Priority加载器的优先级需要大于1000, 1000以下预留给官方加载器
|
||||
@@ -15,4 +15,4 @@ import org.redkale.util.InstanceProvider;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface LockManagerProvider extends InstanceProvider<LockManager> {}
|
||||
public interface LockedManagerProvider extends InstanceProvider<LockedManager> {}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock.spi;
|
||||
package org.redkale.locked.spi;
|
||||
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.annotation.Component;
|
||||
@@ -9,18 +9,18 @@ import org.redkale.annotation.Nullable;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.lock.LockManager;
|
||||
import org.redkale.service.Local;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.locked.LockedManager;
|
||||
|
||||
/** @author zhangjx */
|
||||
@Local
|
||||
@Component
|
||||
@AutoLoad(false)
|
||||
@ResourceType(LockManager.class)
|
||||
public class LockManagerService implements LockManager, Service {
|
||||
@ResourceType(LockedManager.class)
|
||||
public class LockedManagerService implements LockedManager, Service {
|
||||
|
||||
// 是否开启锁
|
||||
protected boolean enabled = true;
|
||||
@@ -34,20 +34,20 @@ public class LockManagerService implements LockManager, Service {
|
||||
// 远程缓存Source
|
||||
protected CacheSource remoteSource;
|
||||
|
||||
protected LockManagerService(@Nullable CacheSource remoteSource) {
|
||||
protected LockedManagerService(@Nullable CacheSource remoteSource) {
|
||||
this.remoteSource = remoteSource;
|
||||
}
|
||||
|
||||
// 一般用于独立组件
|
||||
public static LockManagerService create(@Nullable CacheSource remoteSource) {
|
||||
return new LockManagerService(remoteSource);
|
||||
public static LockedManagerService create(@Nullable CacheSource remoteSource) {
|
||||
return new LockedManagerService(remoteSource);
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public LockManagerService enabled(boolean val) {
|
||||
public LockedManagerService enabled(boolean val) {
|
||||
this.enabled = val;
|
||||
return this;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.lock.spi;
|
||||
package org.redkale.locked.spi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -10,21 +10,21 @@ import java.util.ServiceLoader;
|
||||
import org.redkale.asm.AsmMethodBoost;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.lock.LockManager;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.locked.LockedManager;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class LockModuleEngine extends ModuleEngine {
|
||||
public class LockedModuleEngine extends ModuleEngine {
|
||||
|
||||
// 全局锁管理器
|
||||
private LockManager lockManager;
|
||||
private LockedManager lockManager;
|
||||
|
||||
private AnyValue config;
|
||||
|
||||
public LockModuleEngine(Application application) {
|
||||
public LockedModuleEngine(Application application) {
|
||||
super(application);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class LockModuleEngine extends ModuleEngine {
|
||||
* @return 方法动态扩展器
|
||||
*/
|
||||
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
|
||||
return new LockAsmMethodBoost(remote, serviceClass);
|
||||
return new LockedAsmMethodBoost(remote, serviceClass);
|
||||
}
|
||||
|
||||
/** 结束Application.init方法前被调用 */
|
||||
@@ -68,7 +68,7 @@ public class LockModuleEngine extends ModuleEngine {
|
||||
((Service) this.lockManager).init(this.config);
|
||||
}
|
||||
}
|
||||
this.resourceFactory.register("", LockManager.class, this.lockManager);
|
||||
this.resourceFactory.register("", LockedManager.class, this.lockManager);
|
||||
}
|
||||
|
||||
/** 进入Application.shutdown方法被调用 */
|
||||
@@ -79,22 +79,22 @@ public class LockModuleEngine extends ModuleEngine {
|
||||
}
|
||||
}
|
||||
|
||||
private LockManager createManager(AnyValue conf) {
|
||||
Iterator<LockManagerProvider> it = ServiceLoader.load(LockManagerProvider.class, application.getClassLoader())
|
||||
private LockedManager createManager(AnyValue conf) {
|
||||
Iterator<LockedManagerProvider> it = ServiceLoader.load(LockedManagerProvider.class, application.getClassLoader())
|
||||
.iterator();
|
||||
RedkaleClassLoader.putServiceLoader(LockManagerProvider.class);
|
||||
List<LockManagerProvider> providers = new ArrayList<>();
|
||||
RedkaleClassLoader.putServiceLoader(LockedManagerProvider.class);
|
||||
List<LockedManagerProvider> providers = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
LockManagerProvider provider = it.next();
|
||||
LockedManagerProvider provider = it.next();
|
||||
if (provider != null && provider.acceptsConf(conf)) {
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(
|
||||
provider.getClass(), provider.getClass().getName());
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
for (LockManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
for (LockedManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
return provider.createInstance();
|
||||
}
|
||||
return LockManagerService.create(null).enabled(false);
|
||||
return LockedManagerService.create(null).enabled(false);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -13,17 +13,17 @@ import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cache.Cached;
|
||||
import org.redkale.cached.Cached;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.Range;
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheInstance implements Service {
|
||||
public class CachedInstance implements Service {
|
||||
|
||||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
private CachedManager cacheManager;
|
||||
|
||||
// 修改远程缓存的key值
|
||||
public void updateName(String code, Map<String, Long> map) {
|
||||
@@ -80,7 +80,7 @@ public class CacheInstance implements Service {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
public CachedManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.cache.spi.CacheAsmMethodBoost;
|
||||
import org.redkale.cache.spi.CacheManagerService;
|
||||
import org.redkale.cached.CachedManager;
|
||||
import org.redkale.cached.spi.CachedAsmMethodBoost;
|
||||
import org.redkale.cached.spi.CachedManagerService;
|
||||
import org.redkale.inject.ResourceFactory;
|
||||
import org.redkale.net.AsyncGroup;
|
||||
import org.redkale.net.client.ClientAddress;
|
||||
@@ -21,18 +21,18 @@ import org.redkale.util.Environment;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheInstanceTest {
|
||||
public class CachedInstanceTest {
|
||||
|
||||
private static ResourceFactory resourceFactory;
|
||||
|
||||
private static CacheManagerService manager;
|
||||
private static CachedManagerService manager;
|
||||
|
||||
private static ResourceFactory resourceFactory2;
|
||||
|
||||
private static CacheManagerService manager2;
|
||||
private static CachedManagerService manager2;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CacheInstanceTest test = new CacheInstanceTest();
|
||||
CachedInstanceTest test = new CachedInstanceTest();
|
||||
init();
|
||||
test.run1();
|
||||
test.run2();
|
||||
@@ -45,30 +45,30 @@ public class CacheInstanceTest {
|
||||
remoteSource.init(null);
|
||||
resourceFactory = ResourceFactory.create();
|
||||
resourceFactory.register(new Environment());
|
||||
manager = CacheManagerService.create(remoteSource);
|
||||
manager = CachedManagerService.create(remoteSource);
|
||||
manager.init(null);
|
||||
resourceFactory.register("", CacheManager.class, manager);
|
||||
resourceFactory.register("", CachedManager.class, manager);
|
||||
|
||||
resourceFactory2 = ResourceFactory.create();
|
||||
resourceFactory2.register(new Environment());
|
||||
manager2 = CacheManagerService.create(remoteSource);
|
||||
manager2 = CachedManagerService.create(remoteSource);
|
||||
manager2.init(null);
|
||||
resourceFactory2.register("", CacheManager.class, manager2);
|
||||
resourceFactory2.register("", CachedManager.class, manager2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
Class<CacheInstance> serviceClass = CacheInstance.class;
|
||||
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass);
|
||||
CacheAsmMethodBoost boost2 = new CacheAsmMethodBoost(false, serviceClass);
|
||||
Class<CachedInstance> serviceClass = CachedInstance.class;
|
||||
CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
|
||||
CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
|
||||
SncpRpcGroups grous = new SncpRpcGroups();
|
||||
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
||||
SncpClient client = new SncpClient(
|
||||
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16);
|
||||
CacheInstance instance = Sncp.createLocalService(
|
||||
CachedInstance instance = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
resourceFactory.inject(instance);
|
||||
CacheInstance instance2 = Sncp.createLocalService(
|
||||
CachedInstance instance2 = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
|
||||
resourceFactory2.inject(instance2);
|
||||
System.out.println(instance.getName2());
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.cache.spi.CacheManagerService;
|
||||
import org.redkale.cached.spi.CachedManagerService;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class CacheManagerTest {
|
||||
public class CachedManagerTest {
|
||||
|
||||
private static CacheManagerService manager;
|
||||
private static CachedManagerService manager;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
CacheManagerTest test = new CacheManagerTest();
|
||||
CachedManagerTest test = new CachedManagerTest();
|
||||
init();
|
||||
test.run1();
|
||||
test.run2();
|
||||
@@ -28,7 +28,7 @@ public class CacheManagerTest {
|
||||
public static void init() throws Exception {
|
||||
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
|
||||
remoteSource.init(null);
|
||||
manager = CacheManagerService.create(remoteSource);
|
||||
manager = CachedManagerService.create(remoteSource);
|
||||
manager.init(null);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.test.cache;
|
||||
package org.redkale.test.cached;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -11,39 +11,39 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.cache.spi.CacheAction;
|
||||
import org.redkale.cache.spi.DynForCache;
|
||||
import org.redkale.cached.spi.CachedAction;
|
||||
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 = CacheInstance.class)
|
||||
@ResourceType(CacheInstance.class)
|
||||
public class _DynLocalCacheInstance extends CacheInstance {
|
||||
@SncpDyn(remote = false, type = CachedInstance.class)
|
||||
@ResourceType(CachedInstance.class)
|
||||
public class _DynLocalCacheInstance extends CachedInstance {
|
||||
|
||||
private AnyValue _redkale_conf;
|
||||
|
||||
private String _redkale_mq;
|
||||
|
||||
private CacheAction _redkale_getNameCacheAction1;
|
||||
private CachedAction _redkale_getNameCacheAction1;
|
||||
|
||||
private CacheAction _redkale_getInfoCacheAction2;
|
||||
private CachedAction _redkale_getInfoCacheAction2;
|
||||
|
||||
private CacheAction _redkale_getNameAsyncCacheAction3;
|
||||
private CachedAction _redkale_getNameAsyncCacheAction3;
|
||||
|
||||
private CacheAction _redkale_getInfo2AsyncCacheAction4;
|
||||
private CachedAction _redkale_getInfo2AsyncCacheAction4;
|
||||
|
||||
private CacheAction _redkale_getName2AsyncCacheAction5;
|
||||
private CachedAction _redkale_getName2AsyncCacheAction5;
|
||||
|
||||
private CacheAction _redkale_getInfoAsyncCacheAction6;
|
||||
private CachedAction _redkale_getInfoAsyncCacheAction6;
|
||||
|
||||
private CacheAction _redkale_getName2CacheAction7;
|
||||
private CachedAction _redkale_getName2CacheAction7;
|
||||
|
||||
public _DynLocalCacheInstance() {}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getNameCacheAction1",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -60,7 +60,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfoCacheAction2",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -68,17 +68,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
timeUnit = TimeUnit.SECONDS,
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public File getInfo(CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
public File getInfo(CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<File> supplier = () -> this.getInfo_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoCacheAction2.get(supplier);
|
||||
}
|
||||
|
||||
private File getInfo_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfo(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getNameAsyncCacheAction3",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -95,7 +95,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getNameAsync();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfo2AsyncCacheAction4",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -104,7 +104,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<Map<String, Integer>> getInfo2Async(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier =
|
||||
() -> this.getInfo2Async_afterCache(bean, id, idList, files);
|
||||
@@ -112,12 +112,12 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
}
|
||||
|
||||
private CompletableFuture<Map<String, Integer>> getInfo2Async_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files)
|
||||
throws IOException, InstantiationException {
|
||||
return super.getInfo2Async(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getName2AsyncCacheAction5",
|
||||
hash = "",
|
||||
key = "name",
|
||||
@@ -134,7 +134,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
return super.getName2Async();
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getInfoAsyncCacheAction6",
|
||||
hash = "",
|
||||
key = "info_#{id}_file#{files.one}",
|
||||
@@ -143,17 +143,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
|
||||
remoteExpire = "60",
|
||||
localExpire = "30")
|
||||
public CompletableFuture<File> getInfoAsync(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
ThrowSupplier<CompletableFuture<File>> supplier = () -> this.getInfoAsync_afterCache(bean, id, idList, files);
|
||||
return _redkale_getInfoAsyncCacheAction6.get(supplier, bean, id, idList, files);
|
||||
}
|
||||
|
||||
private CompletableFuture<File> getInfoAsync_afterCache(
|
||||
CacheInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
CachedInstance.ParamBean bean, int id, List<String> idList, Map<String, File> files) {
|
||||
return super.getInfoAsync(bean, id, idList, files);
|
||||
}
|
||||
|
||||
@DynForCache(
|
||||
@DynForCached(
|
||||
dynField = "_redkale_getName2CacheAction7",
|
||||
hash = "",
|
||||
key = "name",
|
||||
Reference in New Issue
Block a user