use of com.alicp.jetcache.anno.support.GlobalCacheConfig in project jetcache by alibaba.
the class TestUtil method createGloableConfig.
public static GlobalCacheConfig createGloableConfig(ConfigProvider configProvider) {
Map localBuilders = new HashMap();
EmbeddedCacheBuilder localBuilder = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder();
// localBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
localBuilders.put(CacheConsts.DEFAULT_AREA, localBuilder);
localBuilders.put("A1", localBuilder);
Map remoteBuilders = new HashMap();
MockRemoteCacheBuilder remoteBuilder = new MockRemoteCacheBuilder();
remoteBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
remoteBuilder.setValueEncoder(KryoValueEncoder.INSTANCE);
remoteBuilder.setValueDecoder(KryoValueDecoder.INSTANCE);
remoteBuilders.put(CacheConsts.DEFAULT_AREA, remoteBuilder);
remoteBuilder = new MockRemoteCacheBuilder();
// remoteBuilder.setKeyConvertor(FastjsonKeyConvertor.INSTANCE);
remoteBuilder.setValueEncoder(KryoValueEncoder.INSTANCE);
remoteBuilder.setValueDecoder(KryoValueDecoder.INSTANCE);
remoteBuilders.put("A1", remoteBuilder);
GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
globalCacheConfig.setConfigProvider(configProvider);
globalCacheConfig.setLocalCacheBuilders(localBuilders);
globalCacheConfig.setRemoteCacheBuilders(remoteBuilders);
// globalCacheConfig.init();
return globalCacheConfig;
}
use of com.alicp.jetcache.anno.support.GlobalCacheConfig 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.GlobalCacheConfig in project jetcache by alibaba.
the class JetCacheInterceptor method invoke.
public Object invoke(final MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
Object obj = invocation.getThis();
CacheInvokeConfig cac = null;
if (obj != null) {
String key = CachePointcut.getKey(method, obj.getClass());
cac = cacheConfigMap.get(key);
}
if (cac == null) {
return invocation.proceed();
}
if (globalCacheConfig == null) {
globalCacheConfig = applicationContext.getBean(GlobalCacheConfig.class);
}
CacheInvokeContext context = globalCacheConfig.getCacheContext().createCacheInvokeContext();
context.setInvoker(invocation::proceed);
context.setMethod(method);
context.setArgs(invocation.getArguments());
context.setCacheInvokeConfig(cac);
context.setHiddenPackages(globalCacheConfig.getHiddenPackages());
return CacheHandler.invoke(context);
}
use of com.alicp.jetcache.anno.support.GlobalCacheConfig in project jetcache by alibaba.
the class JetCacheAutoConfiguration method globalCacheConfig.
@Bean(GLOBAL_CACHE_CONFIG_NAME)
public GlobalCacheConfig globalCacheConfig(SpringConfigProvider configProvider, AutoConfigureBeans autoConfigureBeans, JetCacheProperties props) {
if (_globalCacheConfig != null) {
return _globalCacheConfig;
}
_globalCacheConfig = new GlobalCacheConfig();
_globalCacheConfig.setConfigProvider(configProvider);
_globalCacheConfig.setHiddenPackages(props.getHidePackages());
_globalCacheConfig.setStatIntervalMinutes(props.getStatIntervalMinutes());
_globalCacheConfig.setLocalCacheBuilders(autoConfigureBeans.getLocalCacheBuilders());
_globalCacheConfig.setRemoteCacheBuilders(autoConfigureBeans.getRemoteCacheBuilders());
return _globalCacheConfig;
}
use of com.alicp.jetcache.anno.support.GlobalCacheConfig in project jetcache by alibaba.
the class CacheHandlerTest method setup.
@Before
public void setup() {
globalCacheConfig = new GlobalCacheConfig();
globalCacheConfig.init();
cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
cacheAnnoConfig = new CacheAnnoConfig();
cacheAnnoConfig.setArea(CacheConsts.DEFAULT_AREA);
cacheAnnoConfig.setName(CacheConsts.UNDEFINED_STRING);
cacheAnnoConfig.setEnabled(CacheConsts.DEFAULT_ENABLED);
cacheAnnoConfig.setTimeUnit(TimeUnit.SECONDS);
cacheAnnoConfig.setExpire(100);
cacheAnnoConfig.setCacheType(CacheType.REMOTE);
cacheAnnoConfig.setLocalLimit(CacheConsts.DEFAULT_LOCAL_LIMIT);
cacheAnnoConfig.setCacheNullValue(CacheConsts.DEFAULT_CACHE_NULL_VALUE);
cacheAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
cacheAnnoConfig.setUnless(CacheConsts.UNDEFINED_STRING);
cacheAnnoConfig.setSerialPolicy(CacheConsts.DEFAULT_SERIAL_POLICY);
cacheAnnoConfig.setKeyConvertor(KeyConvertor.FASTJSON);
cacheInvokeConfig = new CacheInvokeConfig();
cacheInvokeConfig.setCacheAnnoConfig(cacheAnnoConfig);
count = new CountClass();
}
Aggregations