use of com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig in project jetcache by alibaba.
the class CacheConfigUtil method parseCacheUpdate.
private static CacheUpdateAnnoConfig parseCacheUpdate(Method m) {
CacheUpdate anno = m.getAnnotation(CacheUpdate.class);
if (anno == null) {
return null;
}
CacheUpdateAnnoConfig cc = new CacheUpdateAnnoConfig();
cc.setArea(anno.area());
cc.setName(anno.name());
if (cc.getName() == null || cc.getName().trim().equals("")) {
throw new CacheConfigException("name is required for @CacheUpdate: " + m.getClass().getName() + "." + m.getName());
}
cc.setKey(anno.key());
cc.setValue(anno.value());
if (cc.getValue() == null || cc.getValue().trim().equals("")) {
throw new CacheConfigException("value is required for @CacheUpdate: " + m.getClass().getName() + "." + m.getName());
}
cc.setCondition(anno.condition());
cc.setMulti(anno.multi());
cc.setDefineMethod(m);
return cc;
}
use of com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig in project jetcache by alibaba.
the class CacheConfigUtil method parse.
public static boolean parse(CacheInvokeConfig cac, Method method) {
boolean hasAnnotation = false;
CachedAnnoConfig cachedConfig = parseCached(method);
if (cachedConfig != null) {
cac.setCachedAnnoConfig(cachedConfig);
hasAnnotation = true;
}
boolean enable = parseEnableCache(method);
if (enable) {
cac.setEnableCacheContext(true);
hasAnnotation = true;
}
List<CacheInvalidateAnnoConfig> invalidateAnnoConfigs = parseCacheInvalidates(method);
if (invalidateAnnoConfigs != null) {
cac.setInvalidateAnnoConfigs(invalidateAnnoConfigs);
hasAnnotation = true;
}
CacheUpdateAnnoConfig updateAnnoConfig = parseCacheUpdate(method);
if (updateAnnoConfig != null) {
cac.setUpdateAnnoConfig(updateAnnoConfig);
hasAnnotation = true;
}
if (cachedConfig != null && (invalidateAnnoConfigs != null || updateAnnoConfig != null)) {
throw new CacheConfigException("@Cached can't coexists with @CacheInvalidate or @CacheUpdate: " + method);
}
return hasAnnotation;
}
use of com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig in project jetcache by alibaba.
the class ExpressionUtilTest method testValue1.
@Test
public void testValue1() {
cic.setCachedAnnoConfig(null);
CacheUpdateAnnoConfig updateAnnoConfig = new CacheUpdateAnnoConfig();
updateAnnoConfig.setDefineMethod(method);
updateAnnoConfig.setValue("#p2");
context.setArgs(new Object[] { "1234", 5678 });
assertEquals(5678, ExpressionUtil.evalValue(context, updateAnnoConfig));
}
use of com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig in project jetcache by alibaba.
the class ExpressionUtilTest method testValue2.
@Test
public void testValue2() {
cic.setCachedAnnoConfig(null);
CacheUpdateAnnoConfig updateAnnoConfig = new CacheUpdateAnnoConfig();
updateAnnoConfig.setDefineMethod(method);
updateAnnoConfig.setValue("#p3");
context.setArgs(new Object[] { "1234", 5678 });
assertNull(ExpressionUtil.evalValue(context, updateAnnoConfig));
}
use of com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig 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);
}
Aggregations