1

Tried to find an answer but I didn't find any information...

I've build a full property based on this following example:

private static Foo _foo;
public static Foo foo {
get 
{
   if (_foo!= null) 
      return _foo;

   //else do some logic and fill _foo;
   _foo = ....;
}};

Question is, when will _foo be null according to life span on the page? On first load of course it will be null but when will it be null again? On recycle? on iisreset? or page reload?

This property sits on an class lib (external dll)

Ziv Weissman
  • 4,250
  • 3
  • 27
  • 57

1 Answers1

2

when will _foo be null according to life span on the page? On first load of course it will be null but when will it be null again? On recycle? on iisreset? or page reload?

It is not bound to a Page, in MVC instance data is relative to a Request and static data is bound to the Application instance.

It will be null each time the Application is restarted, ie on an IIS Recycle or a Reset.

That makes static data rather dubious in Server applications. It can be used as a simple form of caching but be aware that this doesn't 'scale out'. Each server will have its own copy.

Henk Holterman
  • 250,905
  • 30
  • 306
  • 490