Dubbo Cache 操作实例

来源:互联网 发布:遭遇网络贷款诈骗 编辑:程序博客网 时间:2024/06/06 14:14

消费端,可配置缓存


只需在消费端相关方法 或 服务后面添加上: cache="true" 接口缓存此接口的数据,默认缓存大小(cache.size)为: 1000  

【 其中onretrun, onthrow 为切面编程内容,可查询切面操作。 】

<!-- which service to consume? -->      <dubbo:reference id="demoService" interface="com.jgq.dubbo_Service.service.IProcessData" >      <dubbo:method name="deal"  <span style="color:#000099;">onreturn = "demoCallback.onreturn" onthrow="demoCallback.onthrow"</span> <strong><span style="color:#ff0000;">cache="true"</span></strong> />    </dubbo:reference>

场景调用实例:


        CacheService cacheService = (CacheService)context.getBean("cacheService");        // 测试缓存生效,多次调用返回同样的结果。(服务器端自增长返回值)        String fix = null;        for (int i = 0; i < 5; i ++) {            String result = cacheService.findCache("0");            if (fix == null || fix.equals(result)) {                System.out.println("OK: " + result);            } else {                System.err.println("ERROR: " + result);            }            fix = result;            Thread.sleep(500);        }

返回结果: 参数一致,就会返回第一次调用的结果数据。

OK: Finished:0  => time : 2015-12-25 17:24:59
OK: Finished:0  => time : 2015-12-25 17:24:59
OK: Finished:0  => time : 2015-12-25 17:24:59
OK: Finished:0  => time : 2015-12-25 17:24:59
OK: Finished:0  => time : 2015-12-25 17:24:59



0 0
原创粉丝点击