public List<Microcode> getMicrocodeList() {
List<Microcode> cache = (List<Microcode>) cacheBean.get(MICROCODE_KEY);
if (null == cache) {
cache = new ArrayList<Microcode>();
log.debug("CachedObject[key:" + MICROCODE_KEY + "] will be refreshed.");
List<Microcode> results = microcodeDao.findMicrocodeList();
usingFilter(results);
cache.addAll(results);
}
cacheBean.put(MICROCODE_KEY, cache);
return cache;
}
List<Microcode> cache = (List<Microcode>) cacheBean.get(MICROCODE_KEY);
if (null == cache) {
cache = new ArrayList<Microcode>();
log.debug("CachedObject[key:" + MICROCODE_KEY + "] will be refreshed.");
List<Microcode> results = microcodeDao.findMicrocodeList();
usingFilter(results);
cache.addAll(results);
}
cacheBean.put(MICROCODE_KEY, cache);
return cache;
}
这段代码展示了如何在Java中使用缓存。当缓存为空时,从数据库加载数据,进行过滤处理并存入缓存,最后返回缓存数据。

被折叠的 条评论
为什么被折叠?



