NetCoreCacheService.dll

 public IActionResult Index()
        {
            //存入字符串
            MemoryCacheService.SetChacheValue("sname", "刘琪琪");
            //获取字符串缓存
            ViewBag.sbname = MemoryCacheService.GetCacheValue("sname");
            //存入泛型列表
            List<TsetModel> list = new List<TsetModel>();
            for (int i = 0; i < 100; i++)
            {
                TsetModel model = new TsetModel();
                model.Id = i;
                model.Name = "刘奇" + i;
                list.Add(model);
            }
            MemoryCacheService.SetChacheValue("ulist", list);
            //获取list缓存
            var newList = MemoryCacheService.GetList<TsetModel>("ulist");
            return View(newList);
        }

        public IActionResult About()
        {
            TsetModel m = new TsetModel();
            m.Id = 100;
            m.Name = "刘奇";
            //存入model
            MemoryCacheService.SetChacheValue("um", m);
            //获取model
            return View(MemoryCacheService.Get<TsetModel>("um"));
        }
 public class TsetModel
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

 

posted on 2019-10-14 15:32  红磨坊后的白桦树  阅读(268)  评论(0编辑  收藏  举报