调整: 优化缓存工具类

调整: 优化插件提示
This commit is contained in:
ruying408
2024-08-25 22:43:40 +08:00
parent a3179df928
commit 7102d7a561
2 changed files with 26 additions and 1 deletions

View File

@@ -60,6 +60,13 @@ public class CoolCache {
}
}
/**
* 数据来源
*/
public static interface ToCacheData {
Object apply();
}
/**
* 删除缓存
*
@@ -87,6 +94,24 @@ public class CoolCache {
return ifNullValue;
}
/**
* 普通缓存获取
*
* @param key 键
*/
public Object get(String key, Duration duration, ToCacheData toCacheData) {
Object ifNullValue = getIfNullValue(key);
if (ObjUtil.equals(ifNullValue, NULL_VALUE)) {
return null;
}
if (ObjUtil.isEmpty(ifNullValue)) {
Object obj = toCacheData.apply();
set(key, obj, duration.toSeconds());
return obj;
}
return ifNullValue;
}
private Object getIfNullValue(String key) {
if (type.equalsIgnoreCase(CacheType.CAFFEINE.name())) {
Cache.ValueWrapper valueWrapper = cache.get(key);

View File

@@ -64,7 +64,7 @@ public class CoolPluginInvokers {
*/
public static Object invoke(String key, String methodName, Object... params) {
Object beanInstance = dynamicJarLoaderService.getBeanInstance(key);
CoolPreconditions.checkEmpty(beanInstance, "未找到该插件:" + key);
CoolPreconditions.checkEmpty(beanInstance, "未找到该插件:{}, 请前往插件市场进行安装",key);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
// 设置当前线程的上下文类加载器为插件的类加载器