缓存强制刷新:
// spring注入
private SqlMapClient sqlMapClient;
public SqlMapClient getSqlMapClient() {
return sqlMapClient;
}
public void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClient = sqlMapClient;
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String[] cacheModelIds = new String[] { "TBL_SELL.oneDayCache" };
// 刷新指定缓存
if (cacheModelIds.length > 0) {
for (String cacheModelId : cacheModelIds) {
sqlMapClient.flushDataCache(cacheModelId);
}
} else {
// 刷新所有缓存
sqlMapClient.flushDataCache();
}
return null;
}
命中率输出:
SqlMapClientImpl impl = (SqlMapClientImpl) sqlMap;
SqlMapExecutorDelegate delegate = impl.delegate;
Iterator cacheModelNames = delegate.getCacheModelNames();
while(cacheModelNames.hasNext()){
String model = (String) cacheModelNames.next();
CacheModel cacheModel = delegate.getCacheModel(model);
System.out.println(model + ": " + cacheModel.getHitRatio() + "% hit ratio");
}
spring 导致缓存 失效