Search in sources :

Example 1 with ConfigMap

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

the class ProxyUtil method getProxyByAnnotation.

public static <T> T getProxyByAnnotation(T target, ConfigProvider configProvider) {
    final ConfigMap configMap = new ConfigMap();
    processType(configMap, target.getClass());
    Class<?>[] its = ClassUtil.getAllInterfaces(target);
    CacheHandler h = new CacheHandler(target, configMap, () -> configProvider.getCacheContext().createCacheInvokeContext(configMap), configProvider.getGlobalCacheConfig().getHiddenPackages());
    Object o = Proxy.newProxyInstance(target.getClass().getClassLoader(), its, h);
    return (T) o;
}
Also used : ConfigMap(com.alicp.jetcache.anno.support.ConfigMap)

Example 2 with ConfigMap

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

the class CachePointCutTest method setup.

@Before
public void setup() {
    pc = new CachePointcut(new String[] { "com.alicp.jetcache" });
    map = new ConfigMap();
    pc.setCacheConfigMap(map);
}
Also used : ConfigMap(com.alicp.jetcache.anno.support.ConfigMap) Before(org.junit.Before)

Example 3 with ConfigMap

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

the class CacheHandlerInvalidateTest method setup.

@BeforeEach
public void setup() throws Exception {
    GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
    configProvider = new ConfigProvider();
    configProvider.setGlobalCacheConfig(globalCacheConfig);
    configProvider.init();
    cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
    cacheInvokeConfig = new CacheInvokeConfig();
    configMap = new ConfigMap();
    count = new CountClass();
    method = CountClass.class.getMethod("update", String.class, int.class);
    cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
    cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
    invalidateAnnoConfig = new CacheInvalidateAnnoConfig();
    invalidateAnnoConfig.setDefineMethod(method);
    invalidateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
    cacheInvokeConfig.setInvalidateAnnoConfigs(Collections.singletonList(invalidateAnnoConfig));
    invalidateAnnoConfig.setKey("args[0]");
    cacheInvokeConfig.setCachedAnnoConfig(null);
    cacheInvokeContext.setMethod(method);
    cacheInvokeContext.setArgs(new Object[] { "KEY", 1000 });
    cacheInvokeContext.setInvoker(() -> method.invoke(count, cacheInvokeContext.getArgs()));
    cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) CacheInvalidateAnnoConfig(com.alicp.jetcache.anno.support.CacheInvalidateAnnoConfig) ConfigMap(com.alicp.jetcache.anno.support.ConfigMap) ConfigProvider(com.alicp.jetcache.anno.support.ConfigProvider) CountClass(com.alicp.jetcache.testsupport.CountClass) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ConfigMap

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

the class CacheHandlerUpdateTest method setup.

@BeforeEach
public void setup() throws Exception {
    GlobalCacheConfig globalCacheConfig = new GlobalCacheConfig();
    configProvider = new ConfigProvider();
    configProvider.setGlobalCacheConfig(globalCacheConfig);
    configProvider.init();
    cache = LinkedHashMapCacheBuilder.createLinkedHashMapCacheBuilder().keyConvertor(FastjsonKeyConvertor.INSTANCE).buildCache();
    cacheInvokeConfig = new CacheInvokeConfig();
    configMap = new ConfigMap();
    count = new CountClass();
    Method method = CountClass.class.getMethod("update", String.class, int.class);
    cacheInvokeContext = configProvider.getCacheContext().createCacheInvokeContext(configMap);
    cacheInvokeContext.setCacheInvokeConfig(cacheInvokeConfig);
    updateAnnoConfig = new CacheUpdateAnnoConfig();
    updateAnnoConfig.setCondition(CacheConsts.UNDEFINED_STRING);
    updateAnnoConfig.setDefineMethod(method);
    cacheInvokeConfig.setUpdateAnnoConfig(updateAnnoConfig);
    updateAnnoConfig.setKey("args[0]");
    updateAnnoConfig.setValue("args[1]");
    cacheInvokeContext.setMethod(method);
    cacheInvokeContext.setArgs(new Object[] { "K1", 1000 });
    cacheInvokeContext.setInvoker(() -> cacheInvokeContext.getMethod().invoke(count, cacheInvokeContext.getArgs()));
    cacheInvokeContext.setCacheFunction((a, b) -> cache);
}
Also used : GlobalCacheConfig(com.alicp.jetcache.anno.support.GlobalCacheConfig) ConfigMap(com.alicp.jetcache.anno.support.ConfigMap) ConfigProvider(com.alicp.jetcache.anno.support.ConfigProvider) CacheUpdateAnnoConfig(com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig) CountClass(com.alicp.jetcache.testsupport.CountClass) Method(java.lang.reflect.Method) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ConfigMap

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

the class JetCacheInterceptorTest method setup.

@BeforeEach
public void setup() {
    configProvider = TestUtil.createConfigProvider();
    globalCacheConfig = configProvider.getGlobalCacheConfig();
    configProvider.init();
    pc = new CachePointcut(new String[] { "com.alicp.jetcache" });
    ConfigMap map = new ConfigMap();
    pc.setCacheConfigMap(map);
    interceptor = new JetCacheInterceptor();
    interceptor.setCacheConfigMap(map);
    interceptor.configProvider = configProvider;
}
Also used : ConfigMap(com.alicp.jetcache.anno.support.ConfigMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ConfigMap (com.alicp.jetcache.anno.support.ConfigMap)6 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ConfigProvider (com.alicp.jetcache.anno.support.ConfigProvider)2 GlobalCacheConfig (com.alicp.jetcache.anno.support.GlobalCacheConfig)2 CountClass (com.alicp.jetcache.testsupport.CountClass)2 CacheInvalidateAnnoConfig (com.alicp.jetcache.anno.support.CacheInvalidateAnnoConfig)1 CacheUpdateAnnoConfig (com.alicp.jetcache.anno.support.CacheUpdateAnnoConfig)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1