加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Mondrian缓存的处理

发布时间:2020-12-14 02:56:34 所属栏目:大数据 来源:网络整理
导读:1、根据文档中,比较费解,没有看太懂 http://mondrian.pentaho.com/documentation/cache_control.php 并且部分文档的方法无法使用 2、本来打算使用文档中的另一个方法 ? public boolean clearCache() throws Exception { ? ? if ( olapConnection.isWrapper
1、根据文档中,比较费解,没有看太懂
http://mondrian.pentaho.com/documentation/cache_control.php

并且部分文档的方法无法使用
2、本来打算使用文档中的另一个方法
? public boolean clearCache() throws Exception {
? ? if ( olapConnection.isWrapperFor( RolapConnection.class ) ) {
? ? ? System.out.println( "Clearing cache" );
? ? ? RolapConnection rcon = olapConnection.unwrap( RolapConnection.class );
? ? ? rcon.getCacheControl( null ).flushSchemaCache();
? ? }
? ? return true;
? }
? ? 但是最终发现我完全从外部调用,哪里获取RolapConnection呢,于是,此方法宣告失败
3、经过努力,找到别人的方法,此方法可行,原文是

java.util.Iterator<mondrian.rolap.RolapSchema> schemaIterator =? mondrian.rolap.RolapSchema.getRolapSchemas();
while(schemaIterator.hasNext()){
??? mondrian.rolap.RolapSchema schema = schemaIterator.next();
??? mondrian.olap.CacheControl cacheControl = schema.getInternalConnection().getCacheControl(null);
???
??? for (mondrian.olap.Cube cube : schema.getCubes()) {
??????? cacheControl.flush(cacheControl.createMeasuresRegion(cube));
??? }
}

但是对于我用的版本不对应,会报无法转换为Iterator,然后做了稍微修改,如下

List<mondrian.rolap.RolapSchema> schemaList = (List<mondrian.rolap.RolapSchema>) mondrian.rolap.RolapSchema.getRolapSchemas();
? for(mondrian.rolap.RolapSchema schema:schemaList){
? ? ? mondrian.olap.CacheControl cacheControl = schema.getInternalConnection().getCacheControl(null);
? ? ? for (mondrian.olap.Cube cube : schema.getCubes()) {
? ? ? ? ? cacheControl.flush(cacheControl.createMeasuresRegion(cube));
? ? ? }
? }

缓存处理继续研究(基于源码3.6.5版本):
根据官网上的解释,可以使用方法: mondrian.olap.CacheControl.flushSchemaCache()
但是CacheControl是个interface,如何用呢,有接口必然有实现类,找到实现类CacheControlImpl就可以解决了,我的做法如下:
mondrian.olap.CacheControl control=new mondrian.rolap.CacheControlImpl.CacheControlImpl(null);
control.flushSchemaCache();

参数是传入一个mondrian.rolap.RolapConnection类型的对象,但是如果传入为null的时候,调用 flushSchemaCache方法,会执行
? ? RolapSchemaPool.instance().clear();
用来清除SchemaPool中的instance,
RolapSchemaPool其实就是操作一个collection,Pool的实质就是一个 Map ,通过各种方法操作这个Map
其实上面的获取所有的schema然后一个一个清除的方式,和就是用RolapSchemaPool.instance().getRolapSchemas();获取所有的schema,然后循环清除的cube的缓存

此外,根据文档介绍,Mondrian清除缓存还有以下几种方式:
后续继续研究介绍

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读