public ActionResult Menu() { List<ActionInfo> actionList = null; if (Request.Cookies["Menu"] == null) { actionList = GetActionInfos(); //向缓存写入菜单项 string menuCookieId = Guid.NewGuid().ToString(); Response.Cookies["Menu"].Value = menuCookieId; cacheWriter.AddCache(menuCookieId, actionList); } else { string menuCookieId = Request.Cookies["Menu"].Value; actionList = cacheWriter.GetCache(menuCookieId) as List<ActionInfo>; if (actionList == null) { actionList = GetActionInfos(); //向缓存写入菜单项 menuCookieId = Guid.NewGuid().ToString(); Response.Cookies["Menu"].Value = menuCookieId; cacheWriter.AddCache(menuCookieId, actionList); } } return PartialView(actionList); }
public static void AddCache(string key, object value, DateTime expDate) { // 往缓存写: 单机, 分布式 观察者模式可以. 修改一下配置, 就能切换 CacheWriter.AddCache(key, value, expDate); }
public void AddCache(string key, object value, DateTime expDate) { cachewriter.AddCache(key, value, expDate); //new MemcacheWriter().AddCache(key,value,expDate); }
/// <summary> /// 添加一个缓存 /// </summary> /// <param name="key">关键值</param> /// <param name="value">缓存值</param> /// <param name="expDate">过期时间</param> public static void AddCache(string key, object value, DateTime expDate) { CacheWriter.AddCache(key, value, expDate); }