cached包重命名

This commit is contained in:
redkale
2024-06-08 11:07:42 +08:00
parent 0ff3d3133b
commit c60c96a672
27 changed files with 263 additions and 261 deletions

View File

@@ -38,11 +38,11 @@
  以参数code+map.id为key将结果进行远程缓存60毫秒   以参数code+map.id为key将结果进行远程缓存60毫秒
```java ```java
@Resource @Resource
private CacheManager cacheManager; private CachedManager cachedManager;
//实时修改远程缓存的key值 //实时修改远程缓存的key值
public void updateName(String code, Map<String, Long> map) { 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) @Cached(key = "#{code}_#{map.id}", remoteExpire = "60", timeUnit = TimeUnit.MILLISECONDS)
@@ -59,5 +59,5 @@
remote: 远程CacheSource的资源名 remote: 远程CacheSource的资源名
broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true
--> -->
<cache enabled="true" remote="xxx" broadcastable="true"/> <cached enabled="true" remote="xxx" broadcastable="true"/>
``` ```

View File

@@ -49,7 +49,7 @@ serviceid1_name1 serviceid1_name2 serviceid2_name1 serviceid2_name2
remote: 远程CacheSource的资源名 remote: 远程CacheSource的资源名
broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true broadcastable: 存在远程CacheSource时修改数据是否进行广播到其他集群服务中。默认: true
--> -->
<cache enabled="true" remote="xxx" broadcastable="true"/> <cached enabled="true" remote="xxx" broadcastable="true"/>
<!-- <!--
【节点全局唯一】 【节点全局唯一】

View File

@@ -13,8 +13,8 @@ module org.redkale {
exports org.redkale.annotation; exports org.redkale.annotation;
exports org.redkale.boot; exports org.redkale.boot;
exports org.redkale.boot.watch; exports org.redkale.boot.watch;
exports org.redkale.cache; exports org.redkale.cached;
exports org.redkale.cache.spi; exports org.redkale.cached.spi;
exports org.redkale.cluster; exports org.redkale.cluster;
exports org.redkale.cluster.spi; exports org.redkale.cluster.spi;
exports org.redkale.convert; exports org.redkale.convert;
@@ -24,8 +24,8 @@ module org.redkale {
exports org.redkale.convert.proto; exports org.redkale.convert.proto;
exports org.redkale.convert.spi; exports org.redkale.convert.spi;
exports org.redkale.inject; exports org.redkale.inject;
exports org.redkale.lock; exports org.redkale.locked;
exports org.redkale.lock.spi; exports org.redkale.locked.spi;
exports org.redkale.mq; exports org.redkale.mq;
exports org.redkale.mq.spi; exports org.redkale.mq.spi;
exports org.redkale.net; exports org.redkale.net;
@@ -43,7 +43,7 @@ module org.redkale {
exports org.redkale.watch; exports org.redkale.watch;
uses org.redkale.props.spi.PropertiesAgentProvider; 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.cluster.spi.ClusterAgentProvider;
uses org.redkale.convert.spi.ConvertProvider; uses org.redkale.convert.spi.ConvertProvider;
uses org.redkale.mq.spi.MessageAgentProvider; uses org.redkale.mq.spi.MessageAgentProvider;

View File

@@ -22,7 +22,7 @@ import java.util.logging.*;
import org.redkale.annotation.Nonnull; import org.redkale.annotation.Nonnull;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.boot.ClassFilter.FilterEntry; 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.*;
import org.redkale.cluster.spi.ClusterAgent; import org.redkale.cluster.spi.ClusterAgent;
import org.redkale.cluster.spi.ClusterModuleEngine; 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.ResourceEvent;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.inject.ResourceTypeLoader; 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.MessageAgent;
import org.redkale.mq.spi.MessageModuleEngine; import org.redkale.mq.spi.MessageModuleEngine;
import org.redkale.net.*; import org.redkale.net.*;
@@ -312,8 +312,8 @@ public final class Application {
moduleEngines.add(new MessageModuleEngine(this)); moduleEngines.add(new MessageModuleEngine(this));
moduleEngines.add(new ClusterModuleEngine(this)); moduleEngines.add(new ClusterModuleEngine(this));
moduleEngines.add(new ScheduleModuleEngine(this)); moduleEngines.add(new ScheduleModuleEngine(this));
moduleEngines.add(new CacheModuleEngine(this)); moduleEngines.add(new CachedModuleEngine(this));
moduleEngines.add(new LockModuleEngine(this)); moduleEngines.add(new LockedModuleEngine(this));
// 根据本地日志配置文件初始化日志 // 根据本地日志配置文件初始化日志
loggingModule.reconfigLogging(true, appConfig.locaLogProperties); loggingModule.reconfigLogging(true, appConfig.locaLogProperties);

View File

@@ -1,17 +0,0 @@
/*
*
*/
package org.redkale.cache.spi;
import org.redkale.cache.CacheManager;
import org.redkale.util.InstanceProvider;
/**
* 自定义的CacheManager加载器, 如果标记&#64;Priority加载器的优先级需要大于1000 1000以下预留给官方加载器
*
* <p>详情见: https://redkale.org
*
* @author zhangjx
* @since 2.8.0
*/
public interface CacheManagerProvider extends InstanceProvider<CacheManager> {}

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache; package org.redkale.cached;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.METHOD;
@@ -40,7 +40,7 @@ public @interface Cached {
* *
* @return hash * @return hash
*/ */
String hash() default CacheManager.DEFAULT_HASH; String hash() default CachedManager.DEFAULT_HASH;
/** /**
* 本地缓存过期时长 0表示永不过期 -1表示不作本地缓存<br> * 本地缓存过期时长 0表示永不过期 -1表示不作本地缓存<br>

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache; package org.redkale.cached;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.time.Duration; import java.time.Duration;
@@ -16,10 +16,10 @@ import org.redkale.util.ThrowSupplier;
* @author zhangjx * @author zhangjx
* @since 2.8.0 * @since 2.8.0
*/ */
public interface CacheManager { public interface CachedManager {
/** 默认的hash */ /** 默认的hash */
public static final String DEFAULT_HASH = "cache-hash"; public static final String DEFAULT_HASH = "cached-hash";
// -------------------------------------- 本地缓存 -------------------------------------- // -------------------------------------- 本地缓存 --------------------------------------
/** /**

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
@@ -12,7 +12,7 @@ import java.util.concurrent.CompletableFuture;
import org.redkale.annotation.ClassDepends; import org.redkale.annotation.ClassDepends;
import org.redkale.annotation.Nullable; import org.redkale.annotation.Nullable;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.cache.CacheManager; import org.redkale.cached.CachedManager;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.util.Environment; import org.redkale.util.Environment;
@@ -29,15 +29,15 @@ import org.redkale.util.TypeToken;
* @since 2.8.0 * @since 2.8.0
*/ */
@ClassDepends @ClassDepends
public class CacheAction { public class CachedAction {
@Resource @Resource
private Environment environment; private Environment environment;
@Resource @Resource
private CacheManager manager; private CachedManager manager;
private final CacheEntry cached; private final CachedEntry cached;
private final Method method; private final Method method;
@@ -70,7 +70,7 @@ public class CacheAction {
String templetKey; String templetKey;
// 缓存key生成器 // 缓存key生成器
private CacheKeyGenerator keyGenerator; private CachedKeyGenerator keyGenerator;
// 父对象 // 父对象
private Object service; private Object service;
@@ -81,7 +81,7 @@ public class CacheAction {
// 远程缓存过期时长Duration.ZERO为永不过期为null表示不远程缓存 // 远程缓存过期时长Duration.ZERO为永不过期为null表示不远程缓存
private Duration remoteExpire; 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.cached = cached;
this.method = method; this.method = method;
this.nullable = cached.isNullable(); this.nullable = cached.isNullable();
@@ -96,17 +96,17 @@ public class CacheAction {
} }
void init(ResourceFactory resourceFactory, Object service) { void init(ResourceFactory resourceFactory, Object service) {
this.hash = cached.getHash().trim().isEmpty() || CacheManager.DEFAULT_HASH.equals(cached.getHash()) this.hash = cached.getHash().trim().isEmpty() || CachedManager.DEFAULT_HASH.equals(cached.getHash())
? CacheManager.DEFAULT_HASH ? CachedManager.DEFAULT_HASH
: environment.getPropertyValue(cached.getHash()); : environment.getPropertyValue(cached.getHash());
String key = environment.getPropertyValue(cached.getKey()); String key = environment.getPropertyValue(cached.getKey());
this.templetKey = key; this.templetKey = key;
if (key.startsWith("@")) { // 动态加载缓存key生成器 if (key.startsWith("@")) { // 动态加载缓存key生成器
String generatorName = key.substring(1); String generatorName = key.substring(1);
this.keyGenerator = resourceFactory.findChild(generatorName, CacheKeyGenerator.class); this.keyGenerator = resourceFactory.findChild(generatorName, CachedKeyGenerator.class);
} else { } else {
MultiHashKey dynKey = MultiHashKey.create(paramNames, key); MultiHashKey dynKey = MultiHashKey.create(paramNames, key);
this.keyGenerator = CacheKeyGenerator.create(dynKey); this.keyGenerator = CachedKeyGenerator.create(dynKey);
} }
this.localExpire = createDuration(cached.getLocalExpire()); this.localExpire = createDuration(cached.getLocalExpire());
this.remoteExpire = createDuration(cached.getRemoteExpire()); this.remoteExpire = createDuration(cached.getRemoteExpire());
@@ -160,7 +160,7 @@ public class CacheAction {
} }
} }
public CacheEntry getCached() { public CachedEntry getCached() {
return cached; return cached;
} }

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@@ -25,7 +25,7 @@ import org.redkale.asm.MethodVisitor;
import org.redkale.asm.Opcodes; import org.redkale.asm.Opcodes;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
import org.redkale.asm.Type; import org.redkale.asm.Type;
import org.redkale.cache.Cached; import org.redkale.cached.Cached;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.service.LoadMode; import org.redkale.service.LoadMode;
import org.redkale.util.RedkaleClassLoader; import org.redkale.util.RedkaleClassLoader;
@@ -40,17 +40,17 @@ import org.redkale.util.TypeToken;
* *
* @since 2.8.0 * @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 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 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); super(remote, serviceType);
} }
@@ -68,7 +68,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
final List filterAnns, final List filterAnns,
final Method method, final Method method,
final String newMethodName) { final String newMethodName) {
Map<String, CacheAction> actions = this.actionMap; Map<String, CachedAction> actions = this.actionMap;
if (actions == null) { if (actions == null) {
actions = new LinkedHashMap<>(); actions = new LinkedHashMap<>();
this.actionMap = actions; this.actionMap = actions;
@@ -80,7 +80,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
if (!LoadMode.matches(remote, cached.mode())) { if (!LoadMode.matches(remote, cached.mode())) {
return newMethodName; return newMethodName;
} }
if (method.getAnnotation(DynForCache.class) != null) { if (method.getAnnotation(DynForCached.class) != null) {
return newMethodName; return newMethodName;
} }
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { 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); throw new RedkaleException("@" + Cached.class.getSimpleName() + " cannot on void method, but on " + method);
} }
final int actionIndex = fieldIndex.incrementAndGet(); final int actionIndex = fieldIndex.incrementAndGet();
final String rsMethodName = method.getName() + "_afterCache"; final String rsMethodName = method.getName() + "_afterCached";
final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + actionIndex; final String dynFieldName =
fieldPrefix + "_" + method.getName() + CachedAction.class.getSimpleName() + actionIndex;
final AsmMethodBean methodBean = getMethodBean(method); final AsmMethodBean methodBean = getMethodBean(method);
{ // 定义一个新方法调用 this.rsMethodName { // 定义一个新方法调用 this.rsMethodName
final String cacheDynDesc = Type.getDescriptor(DynForCache.class); final String cacheDynDesc = Type.getDescriptor(DynForCached.class);
final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean); final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean);
// mv.setDebug(true); // mv.setDebug(true);
AnnotationVisitor av = mv.visitAnnotation(cacheDynDesc, true); AnnotationVisitor av = mv.visitAnnotation(cacheDynDesc, true);
@@ -123,7 +124,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
Label l1 = new Label(); Label l1 = new Label();
mv.visitLabel(l1); mv.visitLabel(l1);
mv.visitVarInsn(ALOAD, 0); 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()); mv.visitVarInsn(ALOAD, 1 + method.getParameterCount());
Asms.visitInsn(mv, method.getParameterCount()); Asms.visitInsn(mv, method.getParameterCount());
@@ -160,7 +161,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
String throwFuncDesc = Type.getDescriptor(ThrowSupplier.class); String throwFuncDesc = Type.getDescriptor(ThrowSupplier.class);
mv.visitMethodInsn( mv.visitMethodInsn(
INVOKEVIRTUAL, INVOKEVIRTUAL,
CacheAction.class.getName().replace('.', '/'), CachedAction.class.getName().replace('.', '/'),
"get", "get",
"(" + throwFuncDesc + "[Ljava/lang/Object;)Ljava/lang/Object;", "(" + throwFuncDesc + "[Ljava/lang/Object;)Ljava/lang/Object;",
false); false);
@@ -174,8 +175,8 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
mv.visitMaxs(20, 20); mv.visitMaxs(20, 20);
mv.visitEnd(); mv.visitEnd();
CacheAction action = new CacheAction( CachedAction action = new CachedAction(
new CacheEntry(cached), method, serviceType, methodBean.paramNameArray(method), dynFieldName); new CachedEntry(cached), method, serviceType, methodBean.paramNameArray(method), dynFieldName);
actions.put(dynFieldName, action); actions.put(dynFieldName, action);
} }
{ // ThrowSupplier { // ThrowSupplier
@@ -198,7 +199,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
} }
{ // 定义字段 { // 定义字段
FieldVisitor fv = 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(); fv.visitEnd();
} }
if (actions.size() == 1) { if (actions.size() == 1) {
@@ -218,12 +219,12 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
actionMap = new LinkedHashMap<>(); actionMap = new LinkedHashMap<>();
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(clazz); Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(clazz);
for (final Method method : clazz.getDeclaredMethods()) { for (final Method method : clazz.getDeclaredMethods()) {
DynForCache cached = method.getAnnotation(DynForCache.class); DynForCached cached = method.getAnnotation(DynForCached.class);
if (cached != null) { if (cached != null) {
String dynFieldName = cached.dynField(); String dynFieldName = cached.dynField();
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method); AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
CacheAction action = new CacheAction( CachedAction action = new CachedAction(
new CacheEntry(cached), new CachedEntry(cached),
method, method,
serviceType, serviceType,
methodBean.paramNameArray(method), methodBean.paramNameArray(method),

View File

@@ -1,10 +1,10 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.redkale.cache.Cached; import org.redkale.cached.Cached;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
/** /**
@@ -16,7 +16,7 @@ import org.redkale.convert.json.JsonConvert;
* @since 2.8.0 * @since 2.8.0
* *
*/ */
public class CacheEntry { public class CachedEntry {
private String key; private String key;
@@ -30,9 +30,9 @@ public class CacheEntry {
private boolean nullable; private boolean nullable;
public CacheEntry() {} public CachedEntry() {}
public CacheEntry(DynForCache cached) { public CachedEntry(DynForCached cached) {
this.key = cached.key(); this.key = cached.key();
this.hash = cached.hash(); this.hash = cached.hash();
this.localExpire = cached.localExpire(); this.localExpire = cached.localExpire();
@@ -41,7 +41,7 @@ public class CacheEntry {
this.nullable = cached.nullable(); this.nullable = cached.nullable();
} }
public CacheEntry(Cached cached) { public CachedEntry(Cached cached) {
this.key = cached.key(); this.key = cached.key();
this.hash = cached.hash(); this.hash = cached.hash();
this.localExpire = cached.localExpire(); this.localExpire = cached.localExpire();

View File

@@ -2,7 +2,7 @@
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.util.Objects; import java.util.Objects;
import org.redkale.util.MultiHashKey; import org.redkale.util.MultiHashKey;
@@ -17,7 +17,7 @@ import org.redkale.util.MultiHashKey;
* @author zhangjx * @author zhangjx
* @since 2.8.0 * @since 2.8.0
*/ */
public interface CacheKeyGenerator { public interface CachedKeyGenerator {
/** /**
* 根据service和方法名生成key * 根据service和方法名生成key
@@ -27,7 +27,7 @@ public interface CacheKeyGenerator {
* @param params 参数值 * @param params 参数值
* @return key值 * @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 * 根据MultiHashKey生成一个CacheKeyGenerator
* @param key MultiHashKey 不能为空 * @param key MultiHashKey 不能为空
* @return CacheKeyGenerator * @return CachedKeyGenerator
*/ */
public static CacheKeyGenerator create(MultiHashKey key) { public static CachedKeyGenerator create(MultiHashKey key) {
Objects.requireNonNull(key); Objects.requireNonNull(key);
return new CacheKeyGenerator() { return new CachedKeyGenerator() {
@Override @Override
public String generate(Object target, CacheAction action, Object... params) { public String generate(Object target, CachedAction action, Object... params) {
return key.keyFor(params); return key.keyFor(params);
} }

View File

@@ -0,0 +1,17 @@
/*
*
*/
package org.redkale.cached.spi;
import org.redkale.cached.CachedManager;
import org.redkale.util.InstanceProvider;
/**
* 自定义的CachedManager加载器, 如果标记&#64;Priority加载器的优先级需要大于1000 1000以下预留给官方加载器
*
* <p>详情见: https://redkale.org
*
* @author zhangjx
* @since 2.8.0
*/
public interface CachedManagerProvider extends InstanceProvider<CachedManager> {}

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -21,7 +21,7 @@ import org.redkale.annotation.Nullable;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.annotation.ResourceType; import org.redkale.annotation.ResourceType;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import org.redkale.cache.CacheManager; import org.redkale.cached.CachedManager;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
import org.redkale.service.Local; import org.redkale.service.Local;
import org.redkale.service.Service; import org.redkale.service.Service;
@@ -44,8 +44,8 @@ import org.redkale.util.TypeToken;
@Local @Local
@Component @Component
@AutoLoad(false) @AutoLoad(false)
@ResourceType(CacheManager.class) @ResourceType(CachedManager.class)
public class CacheManagerService implements CacheManager, Service { public class CachedManagerService implements CachedManager, Service {
public static final String CACHE_CHANNEL_TOPIC = "cache-update-channel"; 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<>(); 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<>(); private final ConcurrentHashMap<String, CacheAsyncEntry> asyncLock = new ConcurrentHashMap<>();
@@ -81,20 +81,20 @@ public class CacheManagerService implements CacheManager, Service {
protected CacheEventListener remoteListener; protected CacheEventListener remoteListener;
protected CacheManagerService(@Nullable CacheSource remoteSource) { protected CachedManagerService(@Nullable CacheSource remoteSource) {
this.remoteSource = remoteSource; this.remoteSource = remoteSource;
} }
// 一般用于独立组件 // 一般用于独立组件
public static CacheManagerService create(@Nullable CacheSource remoteSource) { public static CachedManagerService create(@Nullable CacheSource remoteSource) {
return new CacheManagerService(remoteSource); return new CachedManagerService(remoteSource);
} }
public boolean enabled() { public boolean enabled() {
return this.enabled; return this.enabled;
} }
public CacheManagerService enabled(boolean val) { public CachedManagerService enabled(boolean val) {
this.enabled = val; this.enabled = val;
return this; return this;
} }
@@ -138,7 +138,7 @@ public class CacheManagerService implements CacheManager, Service {
return enabled; return enabled;
} }
public CacheManagerService addHash(String hash) { public CachedManagerService addHash(String hash) {
this.hashNames.add(hash); this.hashNames.add(hash);
return this; return this;
} }
@@ -172,7 +172,7 @@ public class CacheManagerService implements CacheManager, Service {
@Override @Override
public <T> T localGet(final String hash, final String key, final Type type) { public <T> T localGet(final String hash, final String key, final Type type) {
checkEnable(); 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 @Override
public <T> T remoteGet(final String hash, final String key, final Type type) { public <T> T remoteGet(final String hash, final String key, final Type type) {
checkEnable(); 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 @Override
public <T> CompletableFuture<T> remoteGetAsync(final String hash, final String key, final Type type) { public <T> CompletableFuture<T> remoteGetAsync(final String hash, final String key, final Type type) {
checkEnable(); checkEnable();
CompletableFuture<CacheValue<T>> future = remoteSource.getAsync(idFor(hash, key), loadCacheType(type)); CompletableFuture<CachedValue<T>> future = remoteSource.getAsync(idFor(hash, key), loadCacheType(type));
return future.thenApply(CacheValue::get); return future.thenApply(CachedValue::get);
} }
/** /**
@@ -427,7 +427,7 @@ public class CacheManagerService implements CacheManager, Service {
*/ */
@Override @Override
public <T> T bothGet(final String hash, final String key, final Type type) { 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 @Override
public <T> CompletableFuture<T> bothGetAsync(final String hash, final String key, final Type type) { 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 数据值 * @return 数据值
*/ */
protected <T> T getSet( protected <T> T getSet(
GetterFunc<CacheValue<T>> getter, GetterFunc<CachedValue<T>> getter,
SetterSyncFunc setter, SetterSyncFunc setter,
String hash, String hash,
String key, String key,
@@ -691,16 +691,16 @@ public class CacheManagerService implements CacheManager, Service {
Objects.requireNonNull(supplier); Objects.requireNonNull(supplier);
final Type cacheType = loadCacheType(type); final Type cacheType = loadCacheType(type);
final String id = idFor(hash, key); final String id = idFor(hash, key);
CacheValue<T> cacheVal = getter.get(id, expire, cacheType); CachedValue<T> cacheVal = getter.get(id, expire, cacheType);
if (CacheValue.isValid(cacheVal)) { if (CachedValue.isValid(cacheVal)) {
return cacheVal.getVal(); return cacheVal.getVal();
} }
Function<String, CacheValue> func = k -> { Function<String, CachedValue> func = k -> {
CacheValue<T> oldCacheVal = getter.get(id, expire, cacheType); CachedValue<T> oldCacheVal = getter.get(id, expire, cacheType);
if (CacheValue.isValid(oldCacheVal)) { if (CachedValue.isValid(oldCacheVal)) {
return oldCacheVal; return oldCacheVal;
} }
CacheValue<T> newCacheVal; CachedValue<T> newCacheVal;
try { try {
newCacheVal = toCacheSupplier(nullable, supplier).get(); newCacheVal = toCacheSupplier(nullable, supplier).get();
} catch (RuntimeException e) { } catch (RuntimeException e) {
@@ -708,14 +708,14 @@ public class CacheManagerService implements CacheManager, Service {
} catch (Throwable t) { } catch (Throwable t) {
throw new RedkaleException(t); throw new RedkaleException(t);
} }
if (CacheValue.isValid(newCacheVal)) { if (CachedValue.isValid(newCacheVal)) {
setter.set(id, expire, cacheType, newCacheVal); setter.set(id, expire, cacheType, newCacheVal);
} }
return newCacheVal; return newCacheVal;
}; };
cacheVal = syncLock.computeIfAbsent(id, func); cacheVal = syncLock.computeIfAbsent(id, func);
try { try {
return CacheValue.get(cacheVal); return CachedValue.get(cacheVal);
} finally { } finally {
syncLock.remove(id); syncLock.remove(id);
} }
@@ -736,7 +736,7 @@ public class CacheManagerService implements CacheManager, Service {
* @return 数据值 * @return 数据值
*/ */
protected <T> CompletableFuture<T> getSetAsync( protected <T> CompletableFuture<T> getSetAsync(
GetterFunc<CompletableFuture<CacheValue<T>>> getter, GetterFunc<CompletableFuture<CachedValue<T>>> getter,
SetterAsyncFunc setter, SetterAsyncFunc setter,
String hash, String hash,
String key, String key,
@@ -748,9 +748,9 @@ public class CacheManagerService implements CacheManager, Service {
Objects.requireNonNull(supplier); Objects.requireNonNull(supplier);
final Type cacheType = loadCacheType(type); final Type cacheType = loadCacheType(type);
final String id = idFor(hash, key); 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 -> { return sourceFuture.thenCompose(val -> {
if (CacheValue.isValid(val)) { if (CachedValue.isValid(val)) {
return CompletableFuture.completedFuture(val.getVal()); return CompletableFuture.completedFuture(val.getVal());
} }
final CacheAsyncEntry entry = asyncLock.computeIfAbsent(id, CacheAsyncEntry::new); final CacheAsyncEntry entry = asyncLock.computeIfAbsent(id, CacheAsyncEntry::new);
@@ -761,12 +761,12 @@ public class CacheManagerService implements CacheManager, Service {
if (e != null) { if (e != null) {
entry.fail(e); entry.fail(e);
} }
CacheValue<T> cacheVal = toCacheValue(nullable, v); CachedValue<T> cacheVal = toCacheValue(nullable, v);
if (CacheValue.isValid(cacheVal)) { if (CachedValue.isValid(cacheVal)) {
setter.set(id, expire, cacheType, cacheVal) setter.set(id, expire, cacheType, cacheVal)
.whenComplete((v2, e2) -> entry.success(CacheValue.get(cacheVal))); .whenComplete((v2, e2) -> entry.success(CachedValue.get(cacheVal)));
} else { } else {
entry.success(CacheValue.get(cacheVal)); entry.success(CachedValue.get(cacheVal));
} }
}); });
} catch (Throwable e) { } catch (Throwable e) {
@@ -778,25 +778,25 @@ public class CacheManagerService implements CacheManager, Service {
} }
protected <T> CompletableFuture<Void> localSetCacheAsync( 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); return setCacheAsync(localSource, id, expire, cacheType, cacheVal);
} }
protected <T> CompletableFuture<Void> remoteSetCacheAsync( 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); 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); 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); setCache(remoteSource, id, expire, cacheType, cacheVal);
} }
protected <T> void setCache( 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(); checkEnable();
Objects.requireNonNull(expire); Objects.requireNonNull(expire);
long millis = expire.toMillis(); long millis = expire.toMillis();
@@ -808,7 +808,7 @@ public class CacheManagerService implements CacheManager, Service {
} }
protected <T> CompletableFuture<Void> setCacheAsync( 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(); checkEnable();
Objects.requireNonNull(expire); Objects.requireNonNull(expire);
long millis = expire.toMillis(); 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) { 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( protected <T> CompletableFuture<Void> setCacheAsync(
CacheSource source, String hash, String key, Type type, T value, Duration expire) { 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)); return bothGetCache(idFor(hash, key), expire, loadCacheType(type));
} }
@@ -842,20 +842,20 @@ public class CacheManagerService implements CacheManager, Service {
* @param type 数据类型 * @param type 数据类型
* @return 数据值 * @return 数据值
*/ */
protected <T> CompletableFuture<CacheValue<T>> bothGetCacheAsync( protected <T> CompletableFuture<CachedValue<T>> bothGetCacheAsync(
final String hash, final String key, Duration expire, final Type type) { final String hash, final String key, Duration expire, final Type type) {
return bothGetCacheAsync(idFor(hash, key), expire, loadCacheType(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(); checkEnable();
CacheValue<T> cacheVal = localSource.get(id, cacheType); CachedValue<T> cacheVal = localSource.get(id, cacheType);
if (CacheValue.isValid(cacheVal)) { if (CachedValue.isValid(cacheVal)) {
return cacheVal; return cacheVal;
} }
if (remoteSource != null) { if (remoteSource != null) {
cacheVal = remoteSource.get(id, cacheType); cacheVal = remoteSource.get(id, cacheType);
if (CacheValue.isValid(cacheVal) && expire != null) { if (CachedValue.isValid(cacheVal) && expire != null) {
setCache(localSource, id, expire, cacheType, cacheVal); setCache(localSource, id, expire, cacheType, cacheVal);
} }
return cacheVal; return cacheVal;
@@ -873,16 +873,16 @@ public class CacheManagerService implements CacheManager, Service {
* @param cacheType 数据类型 * @param cacheType 数据类型
* @return 数据值 * @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(); checkEnable();
CacheValue<T> val = localSource.get(id, cacheType); // 内存操作无需异步 CachedValue<T> val = localSource.get(id, cacheType); // 内存操作无需异步
if (CacheValue.isValid(val)) { if (CachedValue.isValid(val)) {
return CompletableFuture.completedFuture(val); return CompletableFuture.completedFuture(val);
} }
if (remoteSource != null) { if (remoteSource != null) {
CompletableFuture<CacheValue<T>> future = remoteSource.getAsync(id, cacheType); CompletableFuture<CachedValue<T>> future = remoteSource.getAsync(id, cacheType);
return future.thenApply(v -> { return future.thenApply(v -> {
if (CacheValue.isValid(v) && expire != null) { if (CachedValue.isValid(v) && expire != null) {
setCache(localSource, id, expire, cacheType, v); setCache(localSource, id, expire, cacheType, v);
} }
return v; return v;
@@ -894,7 +894,7 @@ public class CacheManagerService implements CacheManager, Service {
protected void checkEnable() { protected void checkEnable() {
if (!enabled) { 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 缓存值 * @param value 缓存值
* @return CacheValue函数 * @return CacheValue函数
*/ */
protected <T> CacheValue<T> toCacheValue(boolean nullable, T value) { protected <T> CachedValue<T> toCacheValue(boolean nullable, T value) {
if (value == null) { 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 数据函数 * @param supplier 数据函数
* @return CacheValue函数 * @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()); return () -> toCacheValue(nullable, supplier.get());
} }
@@ -955,7 +955,7 @@ public class CacheManagerService implements CacheManager, Service {
*/ */
protected Type loadCacheType(Type type) { protected Type loadCacheType(Type type) {
return cacheValueTypes.computeIfAbsent( 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(); private static final Object NIL = new Object();
@@ -967,12 +967,12 @@ public class CacheManagerService implements CacheManager, Service {
protected static interface SetterSyncFunc { 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 { 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 { protected class CacheAsyncEntry {

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@@ -15,7 +15,7 @@ import java.util.logging.Level;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import org.redkale.boot.ModuleEngine; import org.redkale.boot.ModuleEngine;
import org.redkale.cache.CacheManager; import org.redkale.cached.CachedManager;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.inject.ResourceTypeLoader; import org.redkale.inject.ResourceTypeLoader;
import org.redkale.service.Service; import org.redkale.service.Service;
@@ -32,14 +32,14 @@ import org.redkale.util.RedkaleException;
* @author zhangjx * @author zhangjx
* @since 2.8.0 * @since 2.8.0
*/ */
public class CacheModuleEngine extends ModuleEngine { public class CachedModuleEngine extends ModuleEngine {
// 全局缓存管理器 // 全局缓存管理器
private CacheManager cacheManager; private CachedManager cacheManager;
private AnyValue config; private AnyValue config;
public CacheModuleEngine(Application application) { public CachedModuleEngine(Application application) {
super(application); super(application);
} }
@@ -69,7 +69,7 @@ public class CacheModuleEngine extends ModuleEngine {
*/ */
@Override @Override
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) { public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
return new CacheAsmMethodBoost(remote, serviceClass); return new CachedAsmMethodBoost(remote, serviceClass);
} }
/** 结束Application.init方法前被调用 */ /** 结束Application.init方法前被调用 */
@@ -84,8 +84,8 @@ public class CacheModuleEngine extends ModuleEngine {
((Service) this.cacheManager).init(this.config); ((Service) this.cacheManager).init(this.config);
} }
} }
this.resourceFactory.register("", CacheManager.class, this.cacheManager); this.resourceFactory.register("", CachedManager.class, this.cacheManager);
ConcurrentHashMap<String, CacheKeyGenerator> generatorMap = new ConcurrentHashMap<>(); ConcurrentHashMap<String, CachedKeyGenerator> generatorMap = new ConcurrentHashMap<>();
this.resourceFactory.register(new ResourceTypeLoader() { this.resourceFactory.register(new ResourceTypeLoader() {
@Override @Override
@@ -97,13 +97,13 @@ public class CacheModuleEngine extends ModuleEngine {
Field field, Field field,
Object attachment) { Object attachment) {
try { try {
CacheKeyGenerator generator = rf.find(resourceName, CacheKeyGenerator.class); CachedKeyGenerator generator = rf.find(resourceName, CachedKeyGenerator.class);
if (generator == null) { if (generator == null) {
return generator; return generator;
} }
generator = generatorMap.computeIfAbsent(resourceName, n -> { generator = generatorMap.computeIfAbsent(resourceName, n -> {
for (CacheKeyGenerator instance : for (CachedKeyGenerator instance :
ServiceLoader.load(CacheKeyGenerator.class, application.getClassLoader())) { ServiceLoader.load(CachedKeyGenerator.class, application.getClassLoader())) {
if (Objects.equals(n, instance.name())) { if (Objects.equals(n, instance.name())) {
rf.inject(instance); rf.inject(instance);
if (instance instanceof Service) { if (instance instanceof Service) {
@@ -115,18 +115,18 @@ public class CacheModuleEngine extends ModuleEngine {
return null; return null;
}); });
if (generator != null) { if (generator != null) {
rf.register(resourceName, CacheKeyGenerator.class, generator); rf.register(resourceName, CachedKeyGenerator.class, generator);
} }
return generator; return generator;
} catch (Exception e) { } 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); throw e instanceof RuntimeException ? (RuntimeException) e : new RedkaleException(e);
} }
} }
@Override @Override
public Type resourceType() { public Type resourceType() {
return CacheKeyGenerator.class; return CachedKeyGenerator.class;
} }
}); });
} }
@@ -141,22 +141,23 @@ public class CacheModuleEngine extends ModuleEngine {
} }
} }
private CacheManager createManager(AnyValue conf) { private CachedManager createManager(AnyValue conf) {
Iterator<CacheManagerProvider> it = ServiceLoader.load(CacheManagerProvider.class, application.getClassLoader()) Iterator<CachedManagerProvider> it = ServiceLoader.load(
CachedManagerProvider.class, application.getClassLoader())
.iterator(); .iterator();
RedkaleClassLoader.putServiceLoader(CacheManagerProvider.class); RedkaleClassLoader.putServiceLoader(CachedManagerProvider.class);
List<CacheManagerProvider> providers = new ArrayList<>(); List<CachedManagerProvider> providers = new ArrayList<>();
while (it.hasNext()) { while (it.hasNext()) {
CacheManagerProvider provider = it.next(); CachedManagerProvider provider = it.next();
if (provider != null && provider.acceptsConf(conf)) { if (provider != null && provider.acceptsConf(conf)) {
RedkaleClassLoader.putReflectionPublicConstructors( RedkaleClassLoader.putReflectionPublicConstructors(
provider.getClass(), provider.getClass().getName()); provider.getClass(), provider.getClass().getName());
providers.add(provider); providers.add(provider);
} }
} }
for (CacheManagerProvider provider : InstanceProvider.sort(providers)) { for (CachedManagerProvider provider : InstanceProvider.sort(providers)) {
return provider.createInstance(); return provider.createInstance();
} }
return CacheManagerService.create(null).enabled(false); return CachedManagerService.create(null).enabled(false);
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.cache.spi; package org.redkale.cached.spi;
import org.redkale.convert.ConvertColumn; import org.redkale.convert.ConvertColumn;
import org.redkale.convert.json.JsonConvert; import org.redkale.convert.json.JsonConvert;
@@ -15,26 +15,26 @@ import org.redkale.convert.json.JsonConvert;
* @param <T> 泛型 * @param <T> 泛型
* @since 2.8.0 * @since 2.8.0
*/ */
public class CacheValue<T> { public class CachedValue<T> {
@ConvertColumn(index = 1) @ConvertColumn(index = 1)
private T val; private T val;
public CacheValue() {} public CachedValue() {}
protected CacheValue(T value) { protected CachedValue(T value) {
this.val = value; this.val = value;
} }
public static <T> CacheValue<T> create(T value) { public static <T> CachedValue<T> create(T value) {
return new CacheValue(value); return new CachedValue(value);
} }
public static boolean isValid(CacheValue val) { public static boolean isValid(CachedValue val) {
return val != null; return val != null;
} }
public static <T> T get(CacheValue val) { public static <T> T get(CachedValue val) {
return isValid(val) ? (T) val.getVal() : null; return isValid(val) ? (T) val.getVal() : null;
} }

View File

@@ -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.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -21,7 +21,7 @@ import org.redkale.service.LoadMode;
@Documented @Documented
@Target({METHOD}) @Target({METHOD})
@Retention(RUNTIME) @Retention(RUNTIME)
public @interface DynForCache { public @interface DynForCached {
String dynField(); String dynField();

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.lock; package org.redkale.locked;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.METHOD;

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.lock; package org.redkale.locked;
/** /**
* //TODO 待实现 * //TODO 待实现
@@ -13,4 +13,4 @@ package org.redkale.lock;
* @author zhangjx * @author zhangjx
* @since 2.8.0 * @since 2.8.0
*/ */
public interface LockManager {} public interface LockedManager {}

View File

@@ -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.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
@@ -20,7 +20,7 @@ import org.redkale.service.LoadMode;
@Documented @Documented
@Target({METHOD}) @Target({METHOD})
@Retention(RUNTIME) @Retention(RUNTIME)
public @interface DynForLock { public @interface DynForLocked {
String dynField(); String dynField();

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.lock.spi; package org.redkale.locked.spi;
import static org.redkale.asm.Opcodes.*; import static org.redkale.asm.Opcodes.*;
@@ -18,16 +18,16 @@ import org.redkale.asm.Label;
import org.redkale.asm.MethodVisitor; import org.redkale.asm.MethodVisitor;
import org.redkale.asm.Type; import org.redkale.asm.Type;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.lock.Locked; import org.redkale.locked.Locked;
import org.redkale.service.LoadMode; import org.redkale.service.LoadMode;
import org.redkale.util.RedkaleException; import org.redkale.util.RedkaleException;
/** @author zhangjx */ /** @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); super(remote, serviceType);
} }
@@ -52,7 +52,7 @@ public class LockAsmMethodBoost extends AsmMethodBoost {
if (!LoadMode.matches(remote, locked.mode())) { if (!LoadMode.matches(remote, locked.mode())) {
return newMethodName; return newMethodName;
} }
if (method.getAnnotation(DynForLock.class) != null) { if (method.getAnnotation(DynForLocked.class) != null) {
return newMethodName; return newMethodName;
} }
if (Modifier.isFinal(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) { 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(); final String dynFieldName = fieldPrefix + "_" + method.getName() + "LockAction" + fieldIndex.incrementAndGet();
{ // 定义一个新方法调用 this.rsMethodName { // 定义一个新方法调用 this.rsMethodName
final AsmMethodBean methodBean = getMethodBean(method); 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); final MethodVisitor mv = createMethodVisitor(cw, method, newMethodName, methodBean);
// mv.setDebug(true); // mv.setDebug(true);
Label l0 = new Label(); Label l0 = new Label();

View File

@@ -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.util.InstanceProvider;
import org.redkale.locked.LockedManager;
/** /**
* 自定义的LockManager加载器, 如果标记&#64;Priority加载器的优先级需要大于1000 1000以下预留给官方加载器 * 自定义的LockManager加载器, 如果标记&#64;Priority加载器的优先级需要大于1000 1000以下预留给官方加载器
@@ -15,4 +15,4 @@ import org.redkale.util.InstanceProvider;
* @author zhangjx * @author zhangjx
* @since 2.8.0 * @since 2.8.0
*/ */
public interface LockManagerProvider extends InstanceProvider<LockManager> {} public interface LockedManagerProvider extends InstanceProvider<LockedManager> {}

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.lock.spi; package org.redkale.locked.spi;
import org.redkale.annotation.AutoLoad; import org.redkale.annotation.AutoLoad;
import org.redkale.annotation.Component; import org.redkale.annotation.Component;
@@ -9,18 +9,18 @@ import org.redkale.annotation.Nullable;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.annotation.ResourceType; import org.redkale.annotation.ResourceType;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import org.redkale.lock.LockManager;
import org.redkale.service.Local; import org.redkale.service.Local;
import org.redkale.service.Service; import org.redkale.service.Service;
import org.redkale.source.CacheSource; import org.redkale.source.CacheSource;
import org.redkale.util.AnyValue; import org.redkale.util.AnyValue;
import org.redkale.locked.LockedManager;
/** @author zhangjx */ /** @author zhangjx */
@Local @Local
@Component @Component
@AutoLoad(false) @AutoLoad(false)
@ResourceType(LockManager.class) @ResourceType(LockedManager.class)
public class LockManagerService implements LockManager, Service { public class LockedManagerService implements LockedManager, Service {
// 是否开启锁 // 是否开启锁
protected boolean enabled = true; protected boolean enabled = true;
@@ -34,20 +34,20 @@ public class LockManagerService implements LockManager, Service {
// 远程缓存Source // 远程缓存Source
protected CacheSource remoteSource; protected CacheSource remoteSource;
protected LockManagerService(@Nullable CacheSource remoteSource) { protected LockedManagerService(@Nullable CacheSource remoteSource) {
this.remoteSource = remoteSource; this.remoteSource = remoteSource;
} }
// 一般用于独立组件 // 一般用于独立组件
public static LockManagerService create(@Nullable CacheSource remoteSource) { public static LockedManagerService create(@Nullable CacheSource remoteSource) {
return new LockManagerService(remoteSource); return new LockedManagerService(remoteSource);
} }
public boolean enabled() { public boolean enabled() {
return this.enabled; return this.enabled;
} }
public LockManagerService enabled(boolean val) { public LockedManagerService enabled(boolean val) {
this.enabled = val; this.enabled = val;
return this; return this;
} }

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.lock.spi; package org.redkale.locked.spi;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@@ -10,21 +10,21 @@ import java.util.ServiceLoader;
import org.redkale.asm.AsmMethodBoost; import org.redkale.asm.AsmMethodBoost;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import org.redkale.boot.ModuleEngine; import org.redkale.boot.ModuleEngine;
import org.redkale.lock.LockManager;
import org.redkale.service.Service; import org.redkale.service.Service;
import org.redkale.util.AnyValue; import org.redkale.util.AnyValue;
import org.redkale.util.InstanceProvider; import org.redkale.util.InstanceProvider;
import org.redkale.util.RedkaleClassLoader; import org.redkale.util.RedkaleClassLoader;
import org.redkale.locked.LockedManager;
/** @author zhangjx */ /** @author zhangjx */
public class LockModuleEngine extends ModuleEngine { public class LockedModuleEngine extends ModuleEngine {
// 全局锁管理器 // 全局锁管理器
private LockManager lockManager; private LockedManager lockManager;
private AnyValue config; private AnyValue config;
public LockModuleEngine(Application application) { public LockedModuleEngine(Application application) {
super(application); super(application);
} }
@@ -53,7 +53,7 @@ public class LockModuleEngine extends ModuleEngine {
* @return 方法动态扩展器 * @return 方法动态扩展器
*/ */
public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) { public AsmMethodBoost createAsmMethodBoost(boolean remote, Class serviceClass) {
return new LockAsmMethodBoost(remote, serviceClass); return new LockedAsmMethodBoost(remote, serviceClass);
} }
/** 结束Application.init方法前被调用 */ /** 结束Application.init方法前被调用 */
@@ -68,7 +68,7 @@ public class LockModuleEngine extends ModuleEngine {
((Service) this.lockManager).init(this.config); ((Service) this.lockManager).init(this.config);
} }
} }
this.resourceFactory.register("", LockManager.class, this.lockManager); this.resourceFactory.register("", LockedManager.class, this.lockManager);
} }
/** 进入Application.shutdown方法被调用 */ /** 进入Application.shutdown方法被调用 */
@@ -79,22 +79,22 @@ public class LockModuleEngine extends ModuleEngine {
} }
} }
private LockManager createManager(AnyValue conf) { private LockedManager createManager(AnyValue conf) {
Iterator<LockManagerProvider> it = ServiceLoader.load(LockManagerProvider.class, application.getClassLoader()) Iterator<LockedManagerProvider> it = ServiceLoader.load(LockedManagerProvider.class, application.getClassLoader())
.iterator(); .iterator();
RedkaleClassLoader.putServiceLoader(LockManagerProvider.class); RedkaleClassLoader.putServiceLoader(LockedManagerProvider.class);
List<LockManagerProvider> providers = new ArrayList<>(); List<LockedManagerProvider> providers = new ArrayList<>();
while (it.hasNext()) { while (it.hasNext()) {
LockManagerProvider provider = it.next(); LockedManagerProvider provider = it.next();
if (provider != null && provider.acceptsConf(conf)) { if (provider != null && provider.acceptsConf(conf)) {
RedkaleClassLoader.putReflectionPublicConstructors( RedkaleClassLoader.putReflectionPublicConstructors(
provider.getClass(), provider.getClass().getName()); provider.getClass(), provider.getClass().getName());
providers.add(provider); providers.add(provider);
} }
} }
for (LockManagerProvider provider : InstanceProvider.sort(providers)) { for (LockedManagerProvider provider : InstanceProvider.sort(providers)) {
return provider.createInstance(); return provider.createInstance();
} }
return LockManagerService.create(null).enabled(false); return LockedManagerService.create(null).enabled(false);
} }
} }

View File

@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
package org.redkale.test.cache; package org.redkale.test.cached;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -13,17 +13,17 @@ import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.cache.CacheManager; import org.redkale.cached.Cached;
import org.redkale.cache.Cached; import org.redkale.cached.CachedManager;
import org.redkale.service.Service; import org.redkale.service.Service;
import org.redkale.source.Range; import org.redkale.source.Range;
import org.redkale.util.RedkaleException; import org.redkale.util.RedkaleException;
/** @author zhangjx */ /** @author zhangjx */
public class CacheInstance implements Service { public class CachedInstance implements Service {
@Resource @Resource
private CacheManager cacheManager; private CachedManager cacheManager;
// 修改远程缓存的key值 // 修改远程缓存的key值
public void updateName(String code, Map<String, Long> map) { public void updateName(String code, Map<String, Long> map) {
@@ -80,7 +80,7 @@ public class CacheInstance implements Service {
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
} }
public CacheManager getCacheManager() { public CachedManager getCacheManager() {
return cacheManager; return cacheManager;
} }

View File

@@ -1,15 +1,15 @@
/* /*
* *
*/ */
package org.redkale.test.cache; package org.redkale.test.cached;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.redkale.cache.CacheManager; import org.redkale.cached.CachedManager;
import org.redkale.cache.spi.CacheAsmMethodBoost; import org.redkale.cached.spi.CachedAsmMethodBoost;
import org.redkale.cache.spi.CacheManagerService; import org.redkale.cached.spi.CachedManagerService;
import org.redkale.inject.ResourceFactory; import org.redkale.inject.ResourceFactory;
import org.redkale.net.AsyncGroup; import org.redkale.net.AsyncGroup;
import org.redkale.net.client.ClientAddress; import org.redkale.net.client.ClientAddress;
@@ -21,18 +21,18 @@ import org.redkale.util.Environment;
import org.redkale.util.Utility; import org.redkale.util.Utility;
/** @author zhangjx */ /** @author zhangjx */
public class CacheInstanceTest { public class CachedInstanceTest {
private static ResourceFactory resourceFactory; private static ResourceFactory resourceFactory;
private static CacheManagerService manager; private static CachedManagerService manager;
private static ResourceFactory resourceFactory2; private static ResourceFactory resourceFactory2;
private static CacheManagerService manager2; private static CachedManagerService manager2;
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
CacheInstanceTest test = new CacheInstanceTest(); CachedInstanceTest test = new CachedInstanceTest();
init(); init();
test.run1(); test.run1();
test.run2(); test.run2();
@@ -45,30 +45,30 @@ public class CacheInstanceTest {
remoteSource.init(null); remoteSource.init(null);
resourceFactory = ResourceFactory.create(); resourceFactory = ResourceFactory.create();
resourceFactory.register(new Environment()); resourceFactory.register(new Environment());
manager = CacheManagerService.create(remoteSource); manager = CachedManagerService.create(remoteSource);
manager.init(null); manager.init(null);
resourceFactory.register("", CacheManager.class, manager); resourceFactory.register("", CachedManager.class, manager);
resourceFactory2 = ResourceFactory.create(); resourceFactory2 = ResourceFactory.create();
resourceFactory2.register(new Environment()); resourceFactory2.register(new Environment());
manager2 = CacheManagerService.create(remoteSource); manager2 = CachedManagerService.create(remoteSource);
manager2.init(null); manager2.init(null);
resourceFactory2.register("", CacheManager.class, manager2); resourceFactory2.register("", CachedManager.class, manager2);
} }
@Test @Test
public void run1() throws Exception { public void run1() throws Exception {
Class<CacheInstance> serviceClass = CacheInstance.class; Class<CachedInstance> serviceClass = CachedInstance.class;
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass); CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass);
CacheAsmMethodBoost boost2 = new CacheAsmMethodBoost(false, serviceClass); CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass);
SncpRpcGroups grous = new SncpRpcGroups(); SncpRpcGroups grous = new SncpRpcGroups();
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0); AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
SncpClient client = new SncpClient( SncpClient client = new SncpClient(
"", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16); "", 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); null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
resourceFactory.inject(instance); resourceFactory.inject(instance);
CacheInstance instance2 = Sncp.createLocalService( CachedInstance instance2 = Sncp.createLocalService(
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null); null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
resourceFactory2.inject(instance2); resourceFactory2.inject(instance2);
System.out.println(instance.getName2()); System.out.println(instance.getName2());

View File

@@ -1,24 +1,24 @@
/* /*
* *
*/ */
package org.redkale.test.cache; package org.redkale.test.cached;
import java.time.Duration; import java.time.Duration;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.*; 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.convert.json.JsonConvert;
import org.redkale.source.CacheMemorySource; import org.redkale.source.CacheMemorySource;
import org.redkale.util.Utility; import org.redkale.util.Utility;
/** @author zhangjx */ /** @author zhangjx */
public class CacheManagerTest { public class CachedManagerTest {
private static CacheManagerService manager; private static CachedManagerService manager;
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
CacheManagerTest test = new CacheManagerTest(); CachedManagerTest test = new CachedManagerTest();
init(); init();
test.run1(); test.run1();
test.run2(); test.run2();
@@ -28,7 +28,7 @@ public class CacheManagerTest {
public static void init() throws Exception { public static void init() throws Exception {
CacheMemorySource remoteSource = new CacheMemorySource("cache-remote"); CacheMemorySource remoteSource = new CacheMemorySource("cache-remote");
remoteSource.init(null); remoteSource.init(null);
manager = CacheManagerService.create(remoteSource); manager = CachedManagerService.create(remoteSource);
manager.init(null); manager.init(null);
} }

View File

@@ -1,7 +1,7 @@
/* /*
* *
*/ */
package org.redkale.test.cache; package org.redkale.test.cached;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -11,39 +11,39 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.redkale.annotation.Resource; import org.redkale.annotation.Resource;
import org.redkale.annotation.ResourceType; import org.redkale.annotation.ResourceType;
import org.redkale.cache.spi.CacheAction; import org.redkale.cached.spi.CachedAction;
import org.redkale.cache.spi.DynForCache;
import org.redkale.net.sncp.Sncp.SncpDyn; import org.redkale.net.sncp.Sncp.SncpDyn;
import org.redkale.util.AnyValue; import org.redkale.util.AnyValue;
import org.redkale.util.RedkaleException; import org.redkale.util.RedkaleException;
import org.redkale.util.ThrowSupplier; import org.redkale.util.ThrowSupplier;
import org.redkale.cached.spi.DynForCached;
@Resource(name = "") @Resource(name = "")
@SncpDyn(remote = false, type = CacheInstance.class) @SncpDyn(remote = false, type = CachedInstance.class)
@ResourceType(CacheInstance.class) @ResourceType(CachedInstance.class)
public class _DynLocalCacheInstance extends CacheInstance { public class _DynLocalCacheInstance extends CachedInstance {
private AnyValue _redkale_conf; private AnyValue _redkale_conf;
private String _redkale_mq; 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() {} public _DynLocalCacheInstance() {}
@DynForCache( @DynForCached(
dynField = "_redkale_getNameCacheAction1", dynField = "_redkale_getNameCacheAction1",
hash = "", hash = "",
key = "name", key = "name",
@@ -60,7 +60,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
return super.getName(); return super.getName();
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getInfoCacheAction2", dynField = "_redkale_getInfoCacheAction2",
hash = "", hash = "",
key = "info_#{id}_file#{files.one}", key = "info_#{id}_file#{files.one}",
@@ -68,17 +68,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
timeUnit = TimeUnit.SECONDS, timeUnit = TimeUnit.SECONDS,
remoteExpire = "60", remoteExpire = "60",
localExpire = "30") 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); ThrowSupplier<File> supplier = () -> this.getInfo_afterCache(bean, id, idList, files);
return _redkale_getInfoCacheAction2.get(supplier); return _redkale_getInfoCacheAction2.get(supplier);
} }
private File getInfo_afterCache( 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); return super.getInfo(bean, id, idList, files);
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getNameAsyncCacheAction3", dynField = "_redkale_getNameAsyncCacheAction3",
hash = "", hash = "",
key = "name", key = "name",
@@ -95,7 +95,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
return super.getNameAsync(); return super.getNameAsync();
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getInfo2AsyncCacheAction4", dynField = "_redkale_getInfo2AsyncCacheAction4",
hash = "", hash = "",
key = "info_#{id}_file#{files.one}", key = "info_#{id}_file#{files.one}",
@@ -104,7 +104,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
remoteExpire = "60", remoteExpire = "60",
localExpire = "30") localExpire = "30")
public CompletableFuture<Map<String, Integer>> getInfo2Async( 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 { throws IOException, InstantiationException {
ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier = ThrowSupplier<CompletableFuture<Map<String, Integer>>> supplier =
() -> this.getInfo2Async_afterCache(bean, id, idList, files); () -> this.getInfo2Async_afterCache(bean, id, idList, files);
@@ -112,12 +112,12 @@ public class _DynLocalCacheInstance extends CacheInstance {
} }
private CompletableFuture<Map<String, Integer>> getInfo2Async_afterCache( 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 { throws IOException, InstantiationException {
return super.getInfo2Async(bean, id, idList, files); return super.getInfo2Async(bean, id, idList, files);
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getName2AsyncCacheAction5", dynField = "_redkale_getName2AsyncCacheAction5",
hash = "", hash = "",
key = "name", key = "name",
@@ -134,7 +134,7 @@ public class _DynLocalCacheInstance extends CacheInstance {
return super.getName2Async(); return super.getName2Async();
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getInfoAsyncCacheAction6", dynField = "_redkale_getInfoAsyncCacheAction6",
hash = "", hash = "",
key = "info_#{id}_file#{files.one}", key = "info_#{id}_file#{files.one}",
@@ -143,17 +143,17 @@ public class _DynLocalCacheInstance extends CacheInstance {
remoteExpire = "60", remoteExpire = "60",
localExpire = "30") localExpire = "30")
public CompletableFuture<File> getInfoAsync( 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); ThrowSupplier<CompletableFuture<File>> supplier = () -> this.getInfoAsync_afterCache(bean, id, idList, files);
return _redkale_getInfoAsyncCacheAction6.get(supplier, bean, id, idList, files); return _redkale_getInfoAsyncCacheAction6.get(supplier, bean, id, idList, files);
} }
private CompletableFuture<File> getInfoAsync_afterCache( 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); return super.getInfoAsync(bean, id, idList, files);
} }
@DynForCache( @DynForCached(
dynField = "_redkale_getName2CacheAction7", dynField = "_redkale_getName2CacheAction7",
hash = "", hash = "",
key = "name", key = "name",