配置文件如下:
plugins.add(new EhCachePlugin());//使用EhCache缓存
public void afterJFinalStart() { new CacheThread().run(); }
public class CacheThread extends Thread { @Override public void run() { initUserGroupCache(); } /** * 初始化用户组(角色)缓存 */ public static void initUserGroupCache() { List<Record> groupList = Db.find(" select id,group_name as name from system_user_group "); if (groupList != null) { CacheKit.put("system", App.CACHE_GROUP, JsonKit.toJson(groupList)); } } }
public void doTag() throws JspException, IOException { JspWriter out = getJspContext().getOut(); if (val == null) { val = ""; } String cacheKey = "cache_" + data; JSONArray arr = JSONArray.parseArray(CacheKit.get("system", cacheKey)); if (arr != null && arr.size() > 0) { boolean flag = true; for (int x = 0; x < arr.size(); x++) { out.print("<div class=\"radio-primary col-md-3\"><input type=\"radio\" name=\"" + controlName + "\""); JSONObject jsonObj = arr.getJSONObject(x); String str = ""; if (val == null || "".equals(val.trim())) { if (flag) { str += " checked=\"checked\""; flag = false; } } else if (jsonObj.get("id").toString().equals(val.trim())) { str += " checked=\"checked\""; } str += "/><label>" + jsonObj.get("name") + "</label></div>"; out.print(str); } } out.flush(); }
我项目的核心代码都贴在上面了,现在的问题是我存入缓存的数据会过期,求助这种情况如何处理?系统刚刚启动的时候我的标签是可以取到数据的,但是过了一会就取不会数据了!
项目:JFinal