问题
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