调整: 优化缓存工具类
调整: 优化插件提示
This commit is contained in:
25
src/main/java/com/cool/core/cache/CoolCache.java
vendored
25
src/main/java/com/cool/core/cache/CoolCache.java
vendored
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
// 设置当前线程的上下文类加载器为插件的类加载器
|
||||
|
||||
Reference in New Issue
Block a user