/** * @Title:putAllDataToCache @Type:FlowCache * * @description:query all flows from DB, put to the cache * @date:2014-5-5 下午7:52:04 * @version:v1.0 */ public void putAllDataToCache() { List<Flow> allFlows = new FlowAccessSessionMySQL().queryAllFlow(); EhcacheHandler ehcacheHandler = EhcacheHandler.getInstance(); for (Flow flow : allFlows) { ehcacheHandler.set(EhcacheHandler.FOREVER_CACHE, flow.getId().getValue(), flow); } setAll(allFlows); }
/** * (non-Javadoc) * * <p>Title:get * * @param id * @return * @see com.sogou.qadev.cache.Cache#get(java.lang.String) */ public Flow get(String id) { Flow tmp = null; Object flow = EhcacheHandler.getInstance().get(EhcacheHandler.FOREVER_CACHE, id); if (flow != null) { if (flow instanceof Flow) { tmp = (Flow) flow; } } else { tmp = new FlowAccessSessionMySQL() .queryFlowById(DataAccessFactory.getInstance().createUUID(id)); if (tmp != null) { EhcacheHandler.getInstance().set(EhcacheHandler.FOREVER_CACHE, tmp.getId().getValue(), tmp); } } if (tmp == null) { logger.info("flow id : " + id + " is not in cache"); } return tmp; }