/// <summary> /// 更新单品信息中门店名称 /// </summary> /// <param name="shopid">门店编号</param> /// <param name="name">更新的门店名称</param> void IDishCache.UpdateDishInfoByChangeShopName(int shopid, string name) { if (shopid == 0 || string.IsNullOrEmpty(name)) { throw new ArgumentNullException("shopid or name can not be null"); } string key = string.Format("DB_DI_*_*_*_{0}", shopid); IList <string> keys = Session.Current.ScanAllKeys(key); if (keys != null && keys.Count > 0) { for (int i = 0; i < keys.Count; i++) { DishInfo dish = Session.Current.Get <DishInfo>(keys[i]); if (dish != null) { dish.ShopName = name; //移除之前的 Session.Current.Remove(keys[i]); Session.Current.Set(dish.GetKeyName(), dish); Session.Current.Expire(dish.GetKeyName(), ExpireTime); } } } }
/// <summary> /// 获取单个单品信息 /// </summary> /// <param name="dishId"></param> /// <returns></returns> public DishInfo GetDishInfoById(int dishId) { DishInfo result = null; string key = string.Format("DB_DI_{0}_*", dishId); IList <string> keys = Session.Current.ScanAllKeys(key); if (keys != null && keys.Count > 0) { result = Session.Current.Get <DishInfo>(keys[0]); } else { //从数据库拿取 IList <DishInfo> dishlist = DBConnectionManager.Instance.Reader.Select <DishInfo>(new DishSelectSpefication(dishId.ToString(), 0).Satifasy()); if (dishlist != null && dishlist.Count > 0) { //同步到缓存 result = dishlist[0]; Session.Current.Set(result.GetKeyName(), result); Session.Current.Expire(result.GetKeyName(), ExpireTime); } } return(result); }