aop逻辑加入缓存优化
This commit is contained in:
@@ -24,7 +24,10 @@ package fun.asgc.neutrino.core.aop;
|
||||
import fun.asgc.neutrino.core.aop.proxy.Proxy;
|
||||
import fun.asgc.neutrino.core.aop.proxy.ProxyFactory;
|
||||
import fun.asgc.neutrino.core.aop.proxy.ProxyStrategy;
|
||||
import fun.asgc.neutrino.core.cache.Cache;
|
||||
import fun.asgc.neutrino.core.cache.MemoryCache;
|
||||
import fun.asgc.neutrino.core.util.Assert;
|
||||
import fun.asgc.neutrino.core.util.LockUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -34,9 +37,14 @@ import fun.asgc.neutrino.core.util.Assert;
|
||||
public class Aop {
|
||||
private static final ProxyStrategy proxyStrategy = ProxyStrategy.SUB_CLASS_PROXY;
|
||||
private static final ProxyFactory proxyFactory = Proxy.getProxyFactory(proxyStrategy);
|
||||
private static final Cache<Class<?>, Object> proxyBeanCache = new MemoryCache<>();
|
||||
|
||||
public static <T> T get(Class<T> clazz) {
|
||||
Assert.notNull(proxyFactory, "代理工厂初始化异常!");
|
||||
return proxyFactory.get(clazz);
|
||||
return (T)LockUtil.doubleCheckProcess(() -> !proxyBeanCache.containsKey(clazz),
|
||||
clazz,
|
||||
() -> proxyBeanCache.set(clazz, proxyFactory.get(clazz)),
|
||||
() -> proxyBeanCache.get(clazz)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user