codecamp

Dubbo3 缓存拓展

扩展说明

用请求参数作为 key,缓存返回结果。

扩展接口

org.apache.dubbo.cache.CacheFactory

扩展配置

<dubbo:service cache="lru" />
<!-- 方法级缓存 -->
<dubbo:service><dubbo:method cache="lru" /></dubbo:service> 
<!-- 缺省值设置,当<dubbo:service>没有配置cache属性时,使用此配置 -->
<dubbo:provider cache="xxx,yyy" /> 

已知扩展

  • org.apache.dubbo.cache.support.lru.LruCacheFactory
  • org.apache.dubbo.cache.support.threadlocal.ThreadLocalCacheFactory
  • org.apache.dubbo.cache.support.jcache.JCacheFactory

扩展示例

Maven 项目结构:

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxCacheFactory.java (实现CacheFactory接口)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.cache.CacheFactory (纯文本文件,内容为:xxx=com.xxx.XxxCacheFactory)

XxxCacheFactory.java:

package com.xxx;
 
import org.apache.dubbo.cache.CacheFactory;
 
public class XxxCacheFactory implements CacheFactory {
    public Cache getCache(URL url, String name) {
        return new XxxCache(url, name);
    }
}

XxxCache.java:

package com.xxx;
 
import org.apache.dubbo.cache.Cache;
 
public class XxxCache implements Cache {
    public Cache(URL url, String name) {
        // ...
    }
    public void put(Object key, Object value) {
        // ...
    }
    public Object get(Object key) {
        // ...
    }
}

META-INF/dubbo/org.apache.dubbo.cache.CacheFactory:

xxx=com.xxx.XxxCacheFactory


Dubbo3 容器拓展
Dubbo3 验证扩展
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

介绍与示例

应用级服务发现

动态修改运行态配置项

参考手册

配置中心参考手册

元数据参考手册

API 参考手册

Kubernetes 生命周期对齐探针

在线运维命令参考手册

Telnet 命令参考手册

Maven 插件参考手册

性能优化

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }