问题描述:
访问/system/log-queryJsonGrid一直在数据库中查询,不会被ehcache命中,没有报错信息。
依赖的jar版本:
nutz-1.b.53.jar
nutz-plugins-daocache-1.r.56.jar
ehcache-2.10.2.jar
相关配置文件
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
monitoring="autodetect" dynamicConfig="true" name="hq">
<!-- <diskStore path="java.io.tmpdir/shiro-ehcache"/> -->
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>
<cache name="shiro-activeSessionCache"
maxElementsInMemory="10000"
overflowToDisk="true"
eternal="true"
timeToLiveSeconds="0"
timeToIdleSeconds="0"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="600"/>
</ehcache>
shiro.ini
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
nutzdao_realm = cn.calensoft.shiro.NutDaoRealm
nutzdao_realm.credentialsMatcher = $sha256Matcher
authc = cn.calensoft.shiro.CaptchaFormAuthenticationFilter
authc.loginUrl = /loginCheck.do
logout.redirectUrl= /login.do
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile=classpath:ehcache.xml
nutzdao_realm.cacheManager = $cacheManager
[urls]
/logout.do = logout
/loginCheck.do = authc
ehcache.js
var ioc = {
cacheManager : {
type : "net.sf.ehcache.CacheManager",
factory : "net.sf.ehcache.CacheManager#getCacheManager",
args : ["hq"] // 对应shiro.ini中指定的ehcache.xml中定义的name
}
/*
// 如果不需要shiro初始化的Ehcache, 使用下面的方式配置
cacheManager : {
type : "net.sf.ehcache.CacheManager",
factory : "net.sf.ehcache.CacheManager#create"
}
*/
};
dao.js
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : [ "custom/" ]
}
},
dataSource : {
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
},
fields : {
url : {
java : "$conf.get('db.url')"
},
username : {
java : "$conf.get('db.username')"
},
password : {
java : "$conf.get('db.password')"
},
testWhileIdle : true,
validationQuery : {
java : "$conf.get('db.validationQuery')"
},
maxActive : {
java : "$conf.get('db.maxActive')"
},
filters : "mergeStat",
connectionProperties : "druid.stat.slowSqlMillis=2000"
}
},
dao : {
type : "org.nutz.dao.impl.NutDaoExt",
args : [ {
refer : "dataSource"
} ],
fields : {
executor : {refer:"cacheExecutor"}
}
},
cacheExecutor : {
type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
fields : {
cacheProvider : {refer:"cacheProvider"},
// 需要缓存的表名
cachedTableNames : ["t_system_log","t_system_jqgrid","v_system_jqgrid_col"
//"t_user", "t_role", "t_permission", "t_role_permission"
],
enableWhenTrans : false, // 事务作用域内是否启用,默认false
cache4Null : true // 是否缓存空值,默认true
}
},
// 基于Ehcache的DaoCacheProvider
cacheProvider : {
type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
fields : {
cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
},
events : {
create : "init"
}
}
};
调用部分代码
BaseService.java
/**
*
* @ClassName BaseService
* @Description TODO 基础服务
*/
@InjectName
@IocBean(fields = {"dao"})
public class BaseService extends IdEntityService<Log> {
@Inject
private I18NModule i18NModule;
@Inject protected CacheManager cacheManager;
LogModule.java
package cn.calensoft.module.system;
import javax.servlet.http.HttpServletRequest;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import cn.calensoft.bean.system.Log;
import cn.calensoft.service.BaseService;
import cn.calensoft.tool.Constants;
import cn.calensoft.util.jqgrid.JqFormBean;
/**
*
* @ClassName LogModule
* @Description TODO 系统日志
* @date 2015-4-13
*/
@IocBean
public class LogModule {
@Inject
private BaseService baseService;
/**
*
* @Method: main
* @Description: TODO 跳转页面
* @param
* @return void
* @throws
*/
@At("/system/log-main")
@Ok("jsp:page.system.log-main")
public void main(){
}
/**
*
* @Method: queryJsonGrid
* @Description: TODO 查询数据源构建
* @param @param request
* @param @return
* @return JqFormBean
* @throws
*/
@At("/system/log-queryJsonGrid")
public JqFormBean queryJsonGrid(HttpServletRequest request) {
JqFormBean jq = JqFormBean.convertParasToBean(request);
return baseService.query(jq,Log.class,Constants.EXPORT_LOG);
}
}