use of com.alicp.jetcache.anno.method.CacheInvokeContext in project jetcache by alibaba.
the class CacheContext method createCacheInvokeContext.
public CacheInvokeContext createCacheInvokeContext() {
CacheInvokeContext c = newCacheInvokeContext();
c.setCacheFunction((invokeContext) -> {
CacheAnnoConfig cacheAnnoConfig = invokeContext.getCacheInvokeConfig().getCacheAnnoConfig();
String area = cacheAnnoConfig.getArea();
String cacheName = cacheAnnoConfig.getName();
if (CacheConsts.UNDEFINED_STRING.equalsIgnoreCase(cacheName)) {
cacheName = ClassUtil.generateCacheName(invokeContext.getMethod(), invokeContext.getHiddenPackages());
}
String fullCacheName = area + "_" + cacheName;
return __createOrGetCache(cacheAnnoConfig, area, fullCacheName);
});
return c;
}
use of com.alicp.jetcache.anno.method.CacheInvokeContext in project jetcache by alibaba.
the class JetCacheInterceptor method invoke.
public Object invoke(final MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
Object obj = invocation.getThis();
CacheInvokeConfig cac = null;
if (obj != null) {
String key = CachePointcut.getKey(method, obj.getClass());
cac = cacheConfigMap.get(key);
}
if (cac == null) {
return invocation.proceed();
}
if (globalCacheConfig == null) {
globalCacheConfig = applicationContext.getBean(GlobalCacheConfig.class);
}
CacheInvokeContext context = globalCacheConfig.getCacheContext().createCacheInvokeContext();
context.setInvoker(invocation::proceed);
context.setMethod(method);
context.setArgs(invocation.getArguments());
context.setCacheInvokeConfig(cac);
context.setHiddenPackages(globalCacheConfig.getHiddenPackages());
return CacheHandler.invoke(context);
}
Aggregations