HttpRuntime.Cache vs. HttpContext.Current.Cache in ASP.NET

Lately I'd been using the static Current property of the HttpContext object in ASP.NET to access it's Cache property and cache information in a web app. I was adding these cache entries with dependencies, so that when certain files were modified, the cache would trigger a callback function to reload. However, when testing this, I ran into an unforseen complication: when I modified a file I had specified as a dependancy, and the app tried to add the new data to the cache using HttpContext.Current.Cache, it couldn't because there was no current HttpContext.

The solution was to use HttpRuntime.Cache instead. This, like HttpContext.Current.Cache, represents the cache of the entire app, but does not require a reference to a current HttpContext. Also, I've heard it's a little bit faster.

Comments

Popular Posts

Resolving the "n timer(s) still in the queue" Error In Angular Unit Tests

How to Get Norton Security Suite Firewall to Allow Remote Desktop Connections in Windows

Silent Renew and the "login_required" Error When Using oidc-client

Fixing the "Please add a @Pipe/@Directive/@Component annotation" Error In An Angular App After Upgrading to webpack 4

How to Determine if a Column Exists in a DataReader