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