How can I use System.Web.Caching.Cache in a Console application?

后端 未结 6 585
死守一世寂寞
死守一世寂寞 2021-02-01 03:47

Context: .Net 3.5, C#
I\'d like to have caching mechanism in my Console application.
Instead of re-inventing the wheel, I\'d like to use System.Web.Caching.Cache

6条回答
  •  无人及你
    2021-02-01 04:13

    Just use the Caching Application Block if you don't want to reinvent the wheel. If you still want to use the ASP.NET cache- see here. I'm pretty sure this only works with .NET 2.0 and above though. It simply wasn't possible to use the cache outside of ASP.NET in .NET 1.

    MSDN has a nice big warning on the page for the cache documentation too:

    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.

    For a very lightweight solution, where you don't have to worry about expiration etc, then a dictionary object could suffice.

提交回复
热议问题