Search in sources :

Example 1 with GlobalCacheConfig

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;
}
Also used : EmbeddedCacheBuilder(com.alicp.jetcache.embedded.EmbeddedCacheBuilder) GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with 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);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CacheAnnoConfig(com.alicp.jetcache.anno.support.CacheAnnoConfig)

Example 3 with GlobalCacheConfig

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);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CacheInvokeConfig(com.alicp.jetcache.anno.method.CacheInvokeConfig) CacheInvokeContext(com.alicp.jetcache.anno.method.CacheInvokeContext) Method(java.lang.reflect.Method)

Example 4 with GlobalCacheConfig

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;
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with 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();
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CountClass(com.alicp.jetcache.testsupport.CountClass) CacheAnnoConfig(com.alicp.jetcache.anno.support.CacheAnnoConfig) Before(org.junit.Before)

Aggregations

GlobalCacheConfig (com.alicp.jetcache.anno.support.GlobalCacheConfig)5 CacheAnnoConfig (com.alicp.jetcache.anno.support.CacheAnnoConfig)2 CacheInvokeConfig (com.alicp.jetcache.anno.method.CacheInvokeConfig)1 CacheInvokeContext (com.alicp.jetcache.anno.method.CacheInvokeContext)1 EmbeddedCacheBuilder (com.alicp.jetcache.embedded.EmbeddedCacheBuilder)1 CountClass (com.alicp.jetcache.testsupport.CountClass)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1