use of com.alicp.jetcache.anno.method.CacheInvokeConfig in project jetcache by alibaba.
the class CachePointcut method matchesImpl.
private boolean matchesImpl(Method method, Class targetClass) {
if (!matchesThis(method.getDeclaringClass())) {
return false;
}
if (exclude(targetClass.getName())) {
return false;
}
String key = getKey(method, targetClass);
CacheInvokeConfig cac = cacheConfigMap.getByMethodInfo(key);
if (cac == CacheInvokeConfig.getNoCacheInvokeConfigInstance()) {
return false;
} else if (cac != null) {
return true;
} else {
cac = new CacheInvokeConfig();
CacheConfigUtil.parse(cac, method);
String name = method.getName();
Class<?>[] paramTypes = method.getParameterTypes();
parseByTargetClass(cac, targetClass, name, paramTypes);
if (!cac.isEnableCacheContext() && cac.getCachedAnnoConfig() == null && cac.getInvalidateAnnoConfigs() == null && cac.getUpdateAnnoConfig() == null) {
cacheConfigMap.putByMethodInfo(key, CacheInvokeConfig.getNoCacheInvokeConfigInstance());
return false;
} else {
cacheConfigMap.putByMethodInfo(key, cac);
return true;
}
}
}
use of com.alicp.jetcache.anno.method.CacheInvokeConfig in project jetcache by alibaba.
the class JetCacheInterceptor method invoke.
@Override
public Object invoke(final MethodInvocation invocation) throws Throwable {
if (configProvider == null) {
configProvider = applicationContext.getBean(ConfigProvider.class);
}
if (configProvider != null && globalCacheConfig == null) {
globalCacheConfig = configProvider.getGlobalCacheConfig();
}
if (globalCacheConfig == null || !globalCacheConfig.isEnableMethodCache()) {
return invocation.proceed();
}
Method method = invocation.getMethod();
Object obj = invocation.getThis();
CacheInvokeConfig cac = null;
if (obj != null) {
String key = CachePointcut.getKey(method, obj.getClass());
cac = cacheConfigMap.getByMethodInfo(key);
}
if (cac == null || cac == CacheInvokeConfig.getNoCacheInvokeConfigInstance()) {
return invocation.proceed();
}
CacheInvokeContext context = configProvider.getCacheContext().createCacheInvokeContext(cacheConfigMap);
context.setTargetObject(invocation.getThis());
context.setInvoker(invocation::proceed);
context.setMethod(method);
context.setArgs(invocation.getArguments());
context.setCacheInvokeConfig(cac);
context.setHiddenPackages(globalCacheConfig.getHiddenPackages());
return CacheHandler.invoke(context);
}
use of com.alicp.jetcache.anno.method.CacheInvokeConfig in project jetcache by alibaba.
the class CacheContext method createCacheInvokeContext.
public CacheInvokeContext createCacheInvokeContext(ConfigMap configMap) {
CacheInvokeContext c = newCacheInvokeContext();
c.setCacheFunction((invokeContext, cacheAnnoConfig) -> {
Cache cache = cacheAnnoConfig.getCache();
if (cache == null) {
if (cacheAnnoConfig instanceof CachedAnnoConfig) {
cache = createCacheByCachedConfig((CachedAnnoConfig) cacheAnnoConfig, invokeContext);
} else if ((cacheAnnoConfig instanceof CacheInvalidateAnnoConfig) || (cacheAnnoConfig instanceof CacheUpdateAnnoConfig)) {
CacheInvokeConfig cacheDefineConfig = configMap.getByCacheName(cacheAnnoConfig.getArea(), cacheAnnoConfig.getName());
if (cacheDefineConfig == null) {
String message = "can't find @Cached definition with area=" + cacheAnnoConfig.getArea() + " name=" + cacheAnnoConfig.getName() + ", specified in " + cacheAnnoConfig.getDefineMethod();
CacheConfigException e = new CacheConfigException(message);
logger.error("Cache operation aborted because can't find @Cached definition", e);
return null;
}
cache = createCacheByCachedConfig(cacheDefineConfig.getCachedAnnoConfig(), invokeContext);
}
cacheAnnoConfig.setCache(cache);
}
return cache;
});
return c;
}
Aggregations