本文整理汇总了Java中com.alibaba.dubbo.cache.Cache类的典型用法代码示例。如果您正苦于以下问题:Java Cache类的具体用法?Java Cache怎么用?Java Cache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cache类属于com.alibaba.dubbo.cache包,在下文中一共展示了Cache类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
if (cache != null && key != null) {
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (! result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
}
return invoker.invoke(invocation);
}
示例2: invoke
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (! result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
return invoker.invoke(invocation);
}
示例3: invoke
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws JahhanException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
if (cache != null && key != null) {
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (! result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
}
return invoker.invoke(invocation);
}
示例4: generateNewCache
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
@Override
protected Cache generateNewCache(String cacheName, URL url) {
String mixCache = CacheConfig.getProperty(MIX_CACHE);
if(StringUtils.isEmpty(mixCache)){
throw new IllegalArgumentException("cache.mix must not be null");
}
String caches[] = Constants.COMMA_SPLIT_PATTERN.split(mixCache);
if(caches.length!=2){
throw new IllegalArgumentException("cache.mix must set two caches,but not set "+caches.length+" ");
}
ExtensionLoader cacheFactoryLoader = ExtensionLoader.getExtensionLoader(CacheFactory.class);
CacheFactory l1CacheFactory = (CacheFactory) cacheFactoryLoader.getExtension(caches[0]);
if(l1CacheFactory==null){
throw new IllegalArgumentException("not found CacheFactory extension by name ["+caches[0]+"]");
}
CacheFactory l2CacheFactory = (CacheFactory) cacheFactoryLoader.getExtension(caches[1]);
if(l2CacheFactory==null){
throw new IllegalArgumentException("not found CacheFactory extension by name ["+caches[1]+"]");
}
return new MixCache(l1CacheFactory.getCache(url),l2CacheFactory.getCache(url),cacheName,url);
}
示例5: invoke
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
if (cache != null && key != null) {
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (!result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
}
return invoker.invoke(invocation);
}
示例6: getCache
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
public Cache getCache(URL url) {
String key = url.toFullString();
Cache cache = caches.get(key);
if (cache == null) {
caches.put(key, createCache(url));
cache = caches.get(key);
}
return cache;
}
示例7: createCache
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
@Override
protected Cache createCache(URL url) {
boolean cacheEnable = DubboCacheConfig.isCacheEnable();
if (cacheEnable) {
boolean cacheObject = DubboCacheConfig.isCacheObject();
if (cacheObject) {
return new AppleCacheObject(url);
} else {
return new AppleCacheOrdinary(url);
}
} else {
return noCache;
}
}
示例8: getCache
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
@Override
public Cache getCache(URL url) {
String method=url.getParameter(Constants.METHOD_KEY);
if(!needCache(method)){
return null;
}
String cacheName = generateCacheName(url);
if(CACHE_MAP.containsKey(cacheName)){
return CACHE_MAP.get(cacheName);
}
Cache cache = generateNewCache(cacheName,url);
cache=putCacheIfAbsent(cacheName,cache);
return cache;
}
示例9: putCacheIfAbsent
import com.alibaba.dubbo.cache.Cache; //导入依赖的package包/类
protected Cache putCacheIfAbsent(String cacheName,Cache cache){
if(CACHE_MAP.containsKey(cacheName)){
return CACHE_MAP.get(cacheName);
}
Cache oldCache = CACHE_MAP.putIfAbsent(cacheName, cache);
if(oldCache==null){
return cache;
}
return oldCache;
}