Safe cache-refresh pattern for ASP.net?

You could hook into the Application OnStart event in the global. Asax file and call a method to load the expensive database calls in a seperate thread when the application starts.

Up vote 0 down vote favorite share g+ share fb share tw.

I've got quite a lot of code on my site that looks like this; Item item; if(Cache"foo"! = null) { item = (Item)Cache"foo"; } else { item = database. GetItemFromDatabase(); Cache.

Insert(item, "foo", null, DateTime.Now. AddDays(1), ... } One such instance of this has a rather expensive getItemFromDatabase method (which is the main reason it's cached). The problem I have is that with every release or restart of the application, the cache is cleared and then an army of users come online and hit the above code, which kills our database server.

What is the typical method of dealing with these sorts of scenarios? Asp.net caching link|improve this question edited Nov 21 '11 at 12:49Death2,0451317 asked Nov 21 '11 at 12:42Mikey Hogarth5208 88% accept rate.

You could hook into the Application OnStart event in the global. Asax file and call a method to load the expensive database calls in a seperate thread when the application starts. It may also be an idea to use a specialised class for accessing these properties using a locking pattern to avoid multiple database calls when the initial value is null.

Thank you, your comments got me searching in the right direction, ended up here; stackoverflow.com/questions/39112/… – Mikey Hogarth Nov 21 '11 at 16:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions