Caching objects on httpcontext asp.net core

我是研究僧i 提交于 2021-01-28 10:08:32

问题


I'm trying to migrate from .net framework MVC 5 to .net core 2.0 MVC

good old times I can get or set the cached objects by calling

HttpContext.Current.Application.Lock();
HttpContext.Current.Application["foo"] = bar;
HttpContext.Current.Application.Lock();

but I cant migrated this part of my application to the .net core.

How can I handle this on core 2.0?


回答1:


HttpContext.Current.Application was a feature that was left in to make applications easier to port over from ASP classic. It has been superseded since ASP.NET 1.0 by HttpContext.Current.Cache and since .NET 4.0 by System.Runtime.Caching.

However, all of these caching features are now missing from AspNetCore. There is a lightweight caching option, IMemoryCache that can be used for many scenarios which is similar to HttpContext.Current.Cache. For more scalability, there is also a IDistributedCache.



来源:https://stackoverflow.com/questions/47461484/caching-objects-on-httpcontext-asp-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!