use of com.alicp.jetcache.anno.support.ConfigProvider in project jetcache by alibaba.
the class TestUtil method createConfigProvider.
public static ConfigProvider createConfigProvider() {
ConfigProvider configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(createGloableConfig());
return configProvider;
}
use of com.alicp.jetcache.anno.support.ConfigProvider in project jetcache by alibaba.
the class CacheHandlerInvalidateTest method setup.
@BeforeEach
public void setup() throws Exception {
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(globalCacheConfig);
configProvider.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cacheInvokeConfig = new CacheInvokeConfig();
configMap = new ConfigMap();
count = new CountClass();
method = CountClass.class.getMethod("update", String.class, int.class);
cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
invalidateAnnoConfig = new CacheInvalidateAnnoConfig();
invalidateAnnoConfig.setDefineMethod(method);
invalidateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
cacheInvokeConfig.setInvalidateAnnoConfigs(Collections.singletonList(invalidateAnnoConfig));
invalidateAnnoConfig.setKey("args[0]");
cacheInvokeConfig.setCachedAnnoConfig(null);
cacheInvokeContext.setMethod(method);
cacheInvokeContext.setArgs(new Object[] { "KEY", 1000 });
cacheInvokeContext.setInvoker(() -> method.invoke(count, cacheInvokeContext.getArgs()));
cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
use of com.alicp.jetcache.anno.support.ConfigProvider in project jetcache by alibaba.
the class CacheHandlerUpdateTest method setup.
@BeforeEach
public void setup() throws Exception {
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
configProvider = new ConfigProvider();
configProvider.setGlobalCacheConfig(globalCacheConfig);
configProvider.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cacheInvokeConfig = new CacheInvokeConfig();
configMap = new ConfigMap();
count = new CountClass();
Method method = CountClass.class.getMethod("update", String.class, int.class);
cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
updateAnnoConfig = new CacheUpdateAnnoConfig();
updateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
updateAnnoConfig.setDefineMethod(method);
cacheInvokeConfig.setUpdateAnnoConfig(updateAnnoConfig);
updateAnnoConfig.setKey("args[0]");
updateAnnoConfig.setValue("args[1]");
cacheInvokeContext.setMethod(method);
cacheInvokeContext.setArgs(new Object[] { "K1", 1000 });
cacheInvokeContext.setInvoker(() -> cacheInvokeContext.getMethod().invoke(count, cacheInvokeContext.getArgs()));
cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
use of com.alicp.jetcache.anno.support.ConfigProvider 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);
}
Aggregations