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);
}
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;
}
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));
}
Aggregations