How can I access HTTP Cache in a C# class library ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With