Mondrian3.x 缓存的处理
mondrian3 OpenSource OpenBI    2017-07-19 23:22:56    952   
lightingfire   mondrian3 OpenSource OpenBI

1、根据文档中,比较费解,没有看太懂(并且部分文档的方法无法使用):http://mondrian.pentaho.com/documentation/cache_control.php

 

2、本来打算使用文档中的另一个方法

但是最终发现我完全从外部调用,哪里获取RolapConnection呢,于是,此方法宣告失败

  1. public boolean clearCache() throws Exception {
  2.     if ( olapConnection.isWrapperFor( RolapConnection.class ) ) {
  3.       System.out.println( "Clearing cache" );
  4.       RolapConnection rcon = olapConnection.unwrap( RolapConnection.class );
  5.       rcon.getCacheControl( null ).flushSchemaCache();
  6.     }
  7.     return true;
  8.   }

 

3、经过努力,找到别人的方法,此方法可行,原文是

  1. java.util.Iterator<mondrian.rolap.RolapSchema> schemaIterator =  mondrian.rolap.RolapSchema.getRolapSchemas();
  2. while(schemaIterator.hasNext()){
  3.     mondrian.rolap.RolapSchema schema = schemaIterator.next();
  4.     mondrian.olap.CacheControl cacheControl = schema.getInternalConnection().getCacheControl(null);
  5.    
  6.     for (mondrian.olap.Cube cube : schema.getCubes()) {
  7.         cacheControl.flush(cacheControl.createMeasuresRegion(cube));
  8.     }
  9. }

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

  1. List<mondrian.rolap.RolapSchema> schemaList = (List<mondrian.rolap.RolapSchema>) mondrian.rolap.RolapSchema.getRolapSchemas();
  2.   for(mondrian.rolap.RolapSchema schema:schemaList){
  3.       mondrian.olap.CacheControl cacheControl = schema.getInternalConnection().getCacheControl(null);
  4.       for (mondrian.olap.Cube cube : schema.getCubes()) {
  5.           cacheControl.flush(cacheControl.createMeasuresRegion(cube));
  6.       }
  7.   }

 

缓存处理继续研究(基于源码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清除缓存还有以下几种方式:

后续继续研究介绍

 


 

by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/

Pre: saiku2.x配置mondrian3.x中Schema中文乱码问题解决方案

Next: 解决生成的saiku2.x文件读取中文乱码的问题


Table of content