Search in sources :

Example 1 with CachedAnnoConfig

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;
}
Also used : CachedAnnoConfig(com.alicp.jetcache.anno.support.CachedAnnoConfig) PenetrationProtectConfig(com.alicp.jetcache.anno.support.PenetrationProtectConfig) RefreshPolicy(com.alicp.jetcache.RefreshPolicy)

Example 2 with CachedAnnoConfig

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;
}
Also used : CachedAnnoConfig(com.alicp.jetcache.anno.support.CachedAnnoConfig) CacheConfigException(com.alicp.jetcache.CacheConfigException) CacheInvalidateAnnoConfig(com.alicp.jetcache.anno.support.CacheInvalidateAnnoConfig) CacheUpdateAnnoConfig(com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig)

Example 3 with CachedAnnoConfig

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);
}
Also used : CachedAnnoConfig(com.alicp.jetcache.anno.support.CachedAnnoConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with 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());
}
Also used : CachedAnnoConfig(com.alicp.jetcache.anno.support.CachedAnnoConfig) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

CachedAnnoConfig (com.alicp.jetcache.anno.support.CachedAnnoConfig)4 CacheConfigException (com.alicp.jetcache.CacheConfigException)1 RefreshPolicy (com.alicp.jetcache.RefreshPolicy)1 CacheInvalidateAnnoConfig (com.alicp.jetcache.anno.support.CacheInvalidateAnnoConfig)1 CacheUpdateAnnoConfig (com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig)1 PenetrationProtectConfig (com.alicp.jetcache.anno.support.PenetrationProtectConfig)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1