1.Java通过memcache进行内容存储
public String getSysDict(String key) { String memKey = "_getSysDict_key_" + key; String dictionaryStr = (String) memcachedClient.get(memKey); if (StringUtils.isNotBlank(dictionaryStr)) {// 缓存读取 return dictionaryStr; } else {// 数据库读取 List<DictionaryDto> list = iCmsSysDao.getDicts(key); String returnJson = JsonUtils.toJsonString(list); if (!list.isEmpty()) {// 放入缓存 memcachedClient.set(memKey, returnJson, new Date(System.currentTimeMillis() + 1000 * 60 * 15)); } return returnJson; } }
2.memcached中获取的字符串转化为map
boolean isRunning() throws Exception {
String value = cmsService.getSysDict("PORTFOLIO_SPREAD_TIME");
Map map = JsonUtils.toJavaBeanList(value, new TypeReference<List<Map<String, String>>>() {
}).get(0);
String[] array = ((String) map.get("keyvalue")).split(",");
String startTime = array[0];
String endTime = array[1];
Date now = new Date();
Date start = DateUtil.parseDate(startTime);
Date end = DateUtil.parseDate(endTime);
if (now.before(start) || now.after(end)) {
return false;
} else {
return true;
}
}