Will the ASP.NET Application Pool utility update the cache on a static object?

I have an application that uses a cache for certain objects and this cache is implemented as static Dictionary

. I am considering using this code for a new ASP.NET project. Since the cache will be stored on the server and not every time the application is launched, I have to refresh the cache from time to time.

My question is this: will the reapplication pool utility rerun the static constructor of my class that sets the cache?

I don't know much about how application pools work, but in my opinion they "close" when the site is not accessed for a long time, and restart when accessed again. During this restart, will static objects be "created" again, or are they retained in memory during the "close" process?

+3


source to share


1 answer


Yes. Static constructors will be re-run.



However, it's still wiser to initialize the data in Application_Start

rather than relying on static constructors because it behaves in a more predictable way.

+2


source







All Articles