Search in sources :

Example 1 with CacheInvokeContext

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;
}
Also used : CacheInvokeContext(com.alicp.jetcache.anno.method.CacheInvokeContext)

Example 2 with CacheInvokeContext

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);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CacheInvokeConfig(com.alicp.jetcache.anno.method.CacheInvokeConfig) CacheInvokeContext(com.alicp.jetcache.anno.method.CacheInvokeContext) Method(java.lang.reflect.Method)

Aggregations

CacheInvokeContext (com.alicp.jetcache.anno.method.CacheInvokeContext)2 CacheInvokeConfig (com.alicp.jetcache.anno.method.CacheInvokeConfig)1 GlobalCacheConfig (com.alicp.jetcache.anno.support.GlobalCacheConfig)1 Method (java.lang.reflect.Method)1