Should we not use the System.Web.Caching.Cache class in a WinForms app?

Should we not use the System.Web.Caching.Cache class in a WinForms app?

巡山小妖精 发布于 2021-11-29 字数 792 浏览 674 回复 3 原文

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.

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


妳是的陽光 2022-06-07 3 楼

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

Cache article.

诠释孤独 2022-06-07 2 楼

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

默嘫て 2022-06-07 1 楼

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