CachedAction

This commit is contained in:
redkale
2024-09-11 11:30:48 +08:00
parent 2b18310050
commit 91eee09e2f

View File

@@ -31,11 +31,6 @@ import org.redkale.util.TypeToken;
@ClassDepends @ClassDepends
public class CachedAction { public class CachedAction {
@Resource
private Environment environment;
private CachedManager manager;
private final CachedEntry cached; private final CachedEntry cached;
private final Method method; private final Method method;
@@ -62,11 +57,16 @@ public class CachedAction {
@Nullable @Nullable
private final String[] paramNames; private final String[] paramNames;
@Resource
private Environment environment;
private CachedManager manager;
// 缓存名称 // 缓存名称
final String name; private String name;
// 模板key // 模板key
final String key; private String key;
// 缓存key生成器 // 缓存key生成器
private CachedKeyGenerator keyGenerator; private CachedKeyGenerator keyGenerator;
@@ -96,19 +96,20 @@ public class CachedAction {
} }
String init(ResourceFactory resourceFactory, Object service) { String init(ResourceFactory resourceFactory, Object service) {
this.manager = resourceFactory.load(cached.getManager(), CachedManager.class); this.manager = resourceFactory.load(environment.getPropertyValue(cached.getManager()), CachedManager.class);
final String realKey = environment.getPropertyValue(cached.getKey()); this.name = environment.getPropertyValue(cached.getName());
if (realKey.startsWith("@")) { // 动态加载缓存key生成器 this.key = environment.getPropertyValue(cached.getKey());
String generatorName = realKey.substring(1); if (key.startsWith("@")) { // 动态加载缓存key生成器
String generatorName = key.substring(1);
this.keyGenerator = resourceFactory.findChild(generatorName, CachedKeyGenerator.class); this.keyGenerator = resourceFactory.findChild(generatorName, CachedKeyGenerator.class);
} else { } else {
MultiHashKey dynKey = MultiHashKey.create(paramNames, realKey); MultiHashKey dynKey = MultiHashKey.create(paramNames, key);
this.keyGenerator = CachedKeyGenerator.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());
((CachedActionFunc) this.manager).addAction(this); ((CachedActionFunc) this.manager).addAction(this);
return realKey; return key;
} }
@ClassDepends @ClassDepends
@@ -199,7 +200,8 @@ public class CachedAction {
+ ",\"fieldName\":\"" + fieldName + "\"" + ",\"fieldName\":\"" + fieldName + "\""
+ ",\"paramTypes\":" + JsonConvert.root().convertTo(method.getParameterTypes()) + ",\"paramTypes\":" + JsonConvert.root().convertTo(method.getParameterTypes())
+ ",\"paramNames\":" + JsonConvert.root().convertTo(paramNames) + ",\"paramNames\":" + JsonConvert.root().convertTo(paramNames)
+ ",\"templetKey\":\"" + key + "\"" + ",\"name\":\"" + name + "\""
+ ",\"key\":\"" + key + "\""
+ ",\"resultType\":\"" + resultType + "\"" + ",\"resultType\":\"" + resultType + "\""
+ ",\"cache\":" + cached + ",\"cache\":" + cached
+ "}"; + "}";