Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access HTTP Cache in a C# class library?

Tags:

c#

caching

How can I access HTTP Cache in a C# class library ?

like image 834
Shyju Avatar asked May 02 '10 21:05

Shyju


1 Answers

It is recommended that you use System.Web.HttpRuntime.Cache rather than System.Web.HttpContext.Current.Cache, as explained in this article.

Additionally, while the article talks about performance, I've also had issues in the past where HttpContext.Current isn't always available when you'd expect it to be, especially when dealing with asynchronous handlers.

Another thing to note is that if you aren't accessing the cache in the context of an HTTP request, HttpContext won't help you, since there won't be a relevant context for you to access.

like image 164
Daniel Schaffer Avatar answered Oct 09 '22 01:10

Daniel Schaffer