Search in sources :

Example 1 with CacheAnnoConfig

use of com.alicp.jetcache.anno.support.CacheAnnoConfig in project jetcache by alibaba.

the class LazyInitCache method init.

private void init() {
    if (inited) {
        throw new IllegalStateException();
    }
    GlobalCacheConfig globalCacheConfig = beanFactory.getBean(GlobalCacheConfig.class);
    CacheAnnoConfig cac = new CacheAnnoConfig();
    cac.setArea(ann.area());
    cac.setName(ann.name());
    cac.setTimeUnit(ann.timeUnit());
    cac.setExpire(ann.expire());
    cac.setCacheType(ann.cacheType());
    cac.setLocalLimit(ann.localLimit());
    cac.setSerialPolicy(ann.serialPolicy());
    cac.setKeyConvertor(ann.keyConvertor());
    String cacheName = cac.getName();
    if (CacheConsts.UNDEFINED_STRING.equalsIgnoreCase(cacheName)) {
        StringBuilder sb = new StringBuilder();
        String className = field.getDeclaringClass().getName();
        className = ClassUtil.removeHiddenPackage(globalCacheConfig.getHiddenPackages(), className);
        className = ClassUtil.getShortClassName(className);
        sb.append(className);
        sb.append(".").append(field.getName());
        cacheName = sb.toString();
    }
    String fullCacheName = cac.getArea() + "_" + cacheName;
    cache = globalCacheConfig.getCacheContext().__createOrGetCache(cac, ann.area(), fullCacheName);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CacheAnnoConfig(com.alicp.jetcache.anno.support.CacheAnnoConfig)

Example 2 with CacheAnnoConfig

use of com.alicp.jetcache.anno.support.CacheAnnoConfig in project jetcache by alibaba.

the class CacheConfigUtil method parseCacheConfig.

private static CacheAnnoConfig parseCacheConfig(Method m) {
    Cached anno = m.getAnnotation(Cached.class);
    if (anno == null) {
        return null;
    }
    CacheAnnoConfig cc = new CacheAnnoConfig();
    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.setLocalLimit(anno.localLimit());
    cc.setCacheNullValue(anno.cacheNullValue());
    cc.setCondition(anno.condition());
    cc.setUnless(anno.unless());
    cc.setSerialPolicy(anno.serialPolicy());
    cc.setKeyConvertor(anno.keyConvertor());
    return cc;
}
Also used : Cached(com.alicp.jetcache.anno.Cached) CacheAnnoConfig(com.alicp.jetcache.anno.support.CacheAnnoConfig)

Example 3 with CacheAnnoConfig

use of com.alicp.jetcache.anno.support.CacheAnnoConfig in project jetcache by alibaba.

the class ProxyUtilTest method testGetProxy.

@Test
public void testGetProxy() {
    CacheAnnoConfig cac = new CacheAnnoConfig();
    cac.setArea(CacheConsts.DEFAULT_AREA);
    cac.setCacheType(CacheType.REMOTE);
    cac.setCondition(CacheConsts.UNDEFINED_STRING);
    cac.setUnless(CacheConsts.UNDEFINED_STRING);
    cac.setEnabled(true);
    cac.setTimeUnit(TimeUnit.SECONDS);
    cac.setExpire(100);
    cac.setName(CacheConsts.UNDEFINED_STRING);
    cac.setSerialPolicy(CacheConsts.DEFAULT_SERIAL_POLICY);
    cac.setKeyConvertor(KeyConvertor.FASTJSON);
    Count c1 = new CountClass();
    Count c2 = ProxyUtil.getProxy(c1, cac, globalCacheConfig);
    Assert.assertNotEquals(c1.count(), c1.count());
    Assert.assertEquals(c2.count(), c2.count());
    Assert.assertEquals(c2.count(100), c2.count(100));
    Assert.assertEquals(c2.count("S", 100), c2.count("S", 100));
    Assert.assertEquals(c2.count(new DynamicQuery(), 100), c2.count(new DynamicQuery(), 100));
    Assert.assertNotEquals(c2.count(200), c2.count(100));
}
Also used : DynamicQuery(com.alicp.jetcache.test.support.DynamicQuery) CountClass(com.alicp.jetcache.testsupport.CountClass) Count(com.alicp.jetcache.testsupport.Count) CacheAnnoConfig(com.alicp.jetcache.anno.support.CacheAnnoConfig) Test(org.junit.Test)

Aggregations

CacheAnnoConfig (com.alicp.jetcache.anno.support.CacheAnnoConfig)3 Cached (com.alicp.jetcache.anno.Cached)1 GlobalCacheConfig (com.alicp.jetcache.anno.support.GlobalCacheConfig)1 DynamicQuery (com.alicp.jetcache.test.support.DynamicQuery)1 Count (com.alicp.jetcache.testsupport.Count)1 CountClass (com.alicp.jetcache.testsupport.CountClass)1 Test (org.junit.Test)1