当前位置: 首页>>代码示例>>Java>>正文


Java Cache类代码示例

本文整理汇总了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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:CacheFilter.java

示例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);
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:19,代码来源:CacheFilter.java

示例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);
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:21,代码来源:CacheFilter.java

示例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);
}
 
开发者ID:dubboclub,项目名称:dubbo-plus,代码行数:22,代码来源:MixCacheFactory.java

示例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);
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:21,代码来源:CacheFilter.java

示例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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:AbstractCacheFactory.java

示例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;
	}
}
 
开发者ID:xushaomin,项目名称:apple-dubbo,代码行数:15,代码来源:AppleCacheFactory.java

示例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;
}
 
开发者ID:dubboclub,项目名称:dubbo-plus,代码行数:15,代码来源:AbstractCacheFactory.java

示例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;
}
 
开发者ID:dubboclub,项目名称:dubbo-plus,代码行数:11,代码来源:AbstractCacheFactory.java


注:本文中的com.alibaba.dubbo.cache.Cache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。