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; } }