强制刷新Ibatis中的缓存(OSCache)

持久层使用Ibatis,并开启动缓存

后台画面可用如下代码强制刷新(根据缓存ID来刷新,不传递缓存参数时,刷新所有缓存)
// 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;
	}

输出日志
13:57:44,250 DEBUG CacheModel:27 - Cache 'TBL_SELL.oneDayCache': flushed

你可能感兴趣的:(java,spring,cache,ibatis)