在httpcontext asp.net核心上缓存对象 [英] Caching objects on httpcontext asp.net core

查看:72
本文介绍了在httpcontext asp.net核心上缓存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从.net Framework MVC 5迁移到.net core 2.0 MVC

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();

但是我无法将应用程序的这一部分迁移到.net核心.

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

如何在核心2.0上处理此问题?

How can I handle this on core 2.0?

推荐答案

HttpContext.Current.Application 是一项保留的功能,使应用程序更容易从ASP classic移植过来.自从ASP.NET 1.0被 HttpContext.Current.Cache 取代,并且自.NET 4.0被 System.Runtime.Caching 取代.

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.

但是,AspNetCore现在缺少所有这些缓存功能.有一个轻量级的缓存选项, IMemoryCache 可用于许多类似于 HttpContext.Current.Cache 的方案.为了获得更大的可伸缩性,还有一个 IDistributedCache .

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.

这篇关于在httpcontext asp.net核心上缓存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆