I know that most people recommend using HttpRuntime.Cache because it has more flexibility… etc. But what if you want the object to persist in the cache for the life of the application? Is there any big downside to using the Application[] object to cache things?
I know that most people recommend using HttpRuntime.Cache because it has more flexibility… etc.
Share
As long as you don’t abuse the application state, then I don’t see a problem in using it for items that you don’t want to expire. Alternatively I would probably use a static variable near the code that uses it. That way you avoid to go through
HttpApplicationStateand then be forced to have a reference to System.Web if i want to access my data.But be sure to think through how you use the object(s) that you store in
HttpApplicationState. If it’s aDataSetwhich you keep adding stuff to for each request, then at some point you end up eating up too much memory on the web-server. The same could happen if you keep adding items toHttpApplicationStatewhen you process requests, at some point you will force the application to restart.That’s probably the advantage of using Cache in your situation. Consuming larger amounts memory isn’t as fatal because you allow ASP.NET to release the items in your cache when memory becomes scarce.