Should we not use the System.Web.Caching.Cache cla

2019-05-09 23:08发布

I've seen several articles/blog posts that advocate the use of the System.Web.Caching.Cache in applications that are not for the Web, however, the MSDN documentation quite clearly states that

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.

Is the documentation wrong, or should we really not be using this class? If the latter, what could go wrong? Our platform is Winforms/.NET 3.5.

3条回答
Lonely孤独者°
2楼-- · 2019-05-09 23:28

Expired or unused Cache objects cannot be automatically removed if the application is not an ASP.NET application. Therefore, if Cache objects are used outside ASP.NET, the system memory that is reserved for the Cache objects is not released. You cannot manually invoke the internal ASP.NET methods to clean up the cache because the methods are marked as internal and intended for internal use. So its your decision to use it in an outside application at your own risk. System.Web.Caching.Cache object

Scott Hanselman has a article post on it for more details

查看更多
Bombasti
3楼-- · 2019-05-09 23:33

documentation is correct, you can not use asp.net cache in windows application.

Cache article.

查看更多
神经病院院长
4楼-- · 2019-05-09 23:45

You're really not supposed to use it outside of ASP.NET. Here's a good whitepaper on other alternatives, however:

http://msdn.microsoft.com/en-us/library/ms978502.aspx

查看更多
登录 后发表回答