use of com.alicp.jetcache.anno.support.CachedAnnoConfig in project jetcache by alibaba.
the class CacheConfigUtil method parseCached.
private static CachedAnnoConfig parseCached(Method m) {
Cached anno = m.getAnnotation(Cached.class);
if (anno == null) {
return null;
}
CachedAnnoConfig cc = new CachedAnnoConfig();
cc.setArea(anno.area());
cc.setName(anno.name());
cc.setCacheType(anno.cacheType());
cc.setEnabled(anno.enabled());
cc.setTimeUnit(anno.timeUnit());
cc.setExpire(anno.expire());
cc.setLocalExpire(anno.localExpire());
cc.setLocalLimit(anno.localLimit());
cc.setCacheNullValue(anno.cacheNullValue());
cc.setCondition(anno.condition());
cc.setPostCondition(anno.postCondition());
cc.setSerialPolicy(anno.serialPolicy());
cc.setKeyConvertor(anno.keyConvertor());
cc.setKey(anno.key());
cc.setDefineMethod(m);
CacheRefresh cacheRefresh = m.getAnnotation(CacheRefresh.class);
if (cacheRefresh != null) {
RefreshPolicy policy = parseRefreshPolicy(cacheRefresh);
cc.setRefreshPolicy(policy);
}
CachePenetrationProtect protectAnno = m.getAnnotation(CachePenetrationProtect.class);
if (protectAnno != null) {
PenetrationProtectConfig protectConfig = parsePenetrationProtectConfig(protectAnno);
cc.setPenetrationProtectConfig(protectConfig);
}
return cc;
}
use of com.alicp.jetcache.anno.support.CachedAnnoConfig 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.CachedAnnoConfig in project jetcache by alibaba.
the class ExpressionUtilTest method setup.
@BeforeEach
public void setup() throws Exception {
method = ExpressionUtilTest.class.getMethod("targetMethod", String.class, int.class);
context = new CacheInvokeContext();
cachedAnnoConfig = new CachedAnnoConfig();
cachedAnnoConfig.setDefineMethod(method);
cic = new CacheInvokeConfig();
context.setCacheInvokeConfig(cic);
context.getCacheInvokeConfig().setCachedAnnoConfig(cachedAnnoConfig);
}
use of com.alicp.jetcache.anno.support.CachedAnnoConfig in project jetcache by alibaba.
the class CachePointCutTest method testMatches3.
@Test
public void testMatches3() throws Exception {
Method m1 = I3_Parent.class.getMethod("foo");
Method m2 = I3.class.getMethod("foo");
Method m3 = C3.class.getMethod("foo");
Assert.assertTrue(pc.matches(m1, C3.class));
Assert.assertTrue(pc.matches(m2, C3.class));
Assert.assertTrue(pc.matches(m3, C3.class));
Assert.assertTrue(pc.matches(m1, I3.class));
Assert.assertTrue(pc.matches(m2, I3.class));
Assert.assertTrue(pc.matches(m3, I3.class));
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m1, I3.class)).isEnableCacheContext());
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m1, C3.class)).isEnableCacheContext());
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m2, I3.class)).isEnableCacheContext());
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m2, C3.class)).isEnableCacheContext());
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m3, I3.class)).isEnableCacheContext());
Assert.assertTrue(map.getByMethodInfo(CachePointcut.getKey(m3, C3.class)).isEnableCacheContext());
CachedAnnoConfig cac = map.getByMethodInfo(CachePointcut.getKey(m1, I3.class)).getCachedAnnoConfig();
Assert.assertEquals("A1", cac.getArea());
Assert.assertEquals(false, cac.isEnabled());
Assert.assertEquals(1, cac.getExpire());
Assert.assertEquals(CacheType.BOTH, cac.getCacheType());
Assert.assertEquals(2, cac.getLocalLimit());
}
Aggregations