1、根据文档中,比较费解,没有看太懂(并且部分文档的方法无法使用):http://mondrian.pentaho.com/documentation/cache_control.php
2、本来打算使用文档中的另一个方法
但是最终发现我完全从外部调用,哪里获取RolapConnection呢,于是,此方法宣告失败
- 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;
- }
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清除缓存还有以下几种方式:
后续继续研究介绍
by 刘迎光@萤火虫工作室
OpenBI交流群:495266201
MicroService 微服务交流群:217722918
mail: liuyg#liuyingguang.cn
博主首页(防止爬虫):http://blog.liuyingguang.cn
OpenBI问答社区:http://openbi.liuyingguang.cn/