/** * 添加或更新缓存 * * @param id */ public void cacheAdd(Long id) { User user = User.dao.findById(id); CacheKit.put(DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + id, user); CacheKit.put( DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("username"), user); CacheKit.put( DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("email"), user); CacheKit.put( DictKeys.cache_name_system, ThreadParamInit.cacheStart_user + user.getStr("phone"), user); }
/** * 从微信得到accessToken的凭证公共代码块 * * @return */ private static RecevieToken getAccessTokenCommon() { // 参数配置的 appID Param paramAppId = (Param) CacheKit.get( DictKeys.cache_name_system, ThreadParamInit.cacheStart_param + weixin_appID_key); String weixin_appID = paramAppId.getStr("val"); // 参数配置的 appSecret Param paramAppSecret = (Param) CacheKit.get( DictKeys.cache_name_system, ThreadParamInit.cacheStart_param + weixin_appSecret_key); String weixin_appSecret = paramAppSecret.getStr("val"); // 获取地址和参数 StringBuilder sb = new StringBuilder(); sb.append(weixin_token_url).append("?").append("grant_type=client_credential"); sb.append("&appid=").append(weixin_appID); sb.append("&secret=").append(weixin_appSecret); try { // 获取 String jsonStr = ToolHttp.get(true, sb.toString()); RecevieToken recevieToken = JSON.parseObject(jsonStr, RecevieToken.class); if (recevieToken.getAccess_token() != null && !recevieToken.getAccess_token().isEmpty()) { recevieToken.setDate(new Date()); // 设置获取时间 // 放入缓存 CacheKit.put(DictKeys.cache_name_system, weixin_access_token, recevieToken); log.info("获取AccessToken:" + jsonStr); return recevieToken; } return null; } catch (Exception e) { log.error("ToolWeiXin.getAccessToken从微信得到accessToken的凭证异常"); return null; } }
public static void putCache(HttpServletRequest request, Object value) { CacheKit.put(CACHE_NAME, getCacheKey(request), value); }
public void putCache(Object key, Object value) { CacheKit.put(CACHE_NAME, key, value); }