asp.net core 缓存

缓存在内存中 ASP.NET Core

public class HomeController : Controller
    {
        private IMemoryCache cache;

        public HomeController(IMemoryCache cache)
        {
             this.cache = cache;
        }

        public IActionResult Index()
        {
            cache.Set("name", $"shijia{DateTime.Now}", TimeSpan.FromSeconds(10));
            return View();
        }

        public IActionResult About()
        {
            object result;
            string value = cache.TryGetValue("name", out result) ? $"获取缓存name{result}" : "获取缓存失败";
            return Content(value);
        }

猜你喜欢

转载自www.cnblogs.com/tangge/p/10056387.html