在ASP.NET应用程序外部使用HttpRuntime.Cache是​​否可以? [英] Is it OK to use HttpRuntime.Cache outside ASP.NET applications?

查看:67
本文介绍了在ASP.NET应用程序外部使用HttpRuntime.Cache是​​否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scott Hanselman 说是

Scott Hanselman says yes.


将System.Web添加到非Web项目中是使人们感到恐慌的好方法。另一个是在C#应用程序中添加对Microsoft.VisualBasic的引用。

Adding System.Web to your non-web project is a good way to get folks to panic. Another is adding a reference to Microsoft.VisualBasic in a C# application. Both are reasonable and darned useful things to do, though.

MSDN 说不


Cache类不适用于ASP.NET应用程序之外。它经过设计和测试,可在ASP.NET中使用,以为Web应用程序提供缓存。在其他类型的应用程序中,例如控制台应用程序或Windows Forms应用程序,ASP.NET缓存可能无法正常工作。

The Cache class is not intended for use outside of ASP.NET applications. It was designed and tested for use in ASP.NET to provide caching for Web applications. In other types of applications, such as console applications or Windows Forms applications, ASP.NET caching might not work correctly.

所以应该怎么办?我认为吗?

So what should I think?

推荐答案

我知道这个问题很旧,但是为了帮助任何通过搜索找到它的人,它的价值请注意,.net v4包括针对这种情况的新通用缓存。它在System.Runtime.Caching命名空间中:

I realize this question is old, but in the interest of helping anyone who finds this via search, its worth noting that .net v4 includes a new general purpose cache for this type of scenario. It's in the System.Runtime.Caching namespace:

https://msdn.microsoft.com/zh-CN/library/dd997357(v = vs.110).aspx

对默认缓存实例的静态引用是:MemoryCache.Default

The static reference to the default cache instance is: MemoryCache.Default

这篇关于在ASP.NET应用程序外部使用HttpRuntime.Cache是​​否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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