Server farm and fields of classes in session cache

C

cpnet

I'm building some ASP.NET components, and I'd like them to function in a
server farm scenario. I have one class, "AppClass" that contains only
read-only data. I also have a second class, "SessionClass", that stores a
reference to an AppClass i.e:

SessionClass sc = new SessionClass();
sc.AppClass = (AppClass) Page.Application["AnAppClassInstance"];


Consumers of my components will likely create a single instance of AppClass
as an application variable, and share it for all SessionClass instances.
Each session will likely have only one SessionClass instance (though they
might have more). The session class instance(s) will likely be persisted in
the session cache.

Now, here's the problem: If my components are used in a server farm, the
session could switch servers, and thus the AppClass instance that the
SessionClass was referring to, may be an AppClass instance on another
server. If SessionClass is serialized to the session cache, what happens to
the SessionClass.AppClass reference when a SessionClass instance is
serialized/deserialized to a different server? I'm assuming the reference
will still be there (i.e. non-null), but just invalid. Is this correct?

Assuming I'm correct, the best solution I can come up with is to set

SessionClass.AppClass = null;

when an instance of SessionClass is serialized, and later have SessionClass
raise an event if something tries to access SessionClass.AppClass while it's
null. This way, there'll be an easy opportunity to reset
SessionClass.AppClass. Is there a better way to handle this?


(Note that AppClass sets up close to 1 MB of data in an internal DataSet
when it is created, which is why I want to avoid re-creating this class as
much as possible).

Thanks,
cpnet
 
S

Steven Cheng[MSFT]

Hi Cpnet,

As for the shared class instance in server farm scenario problem, I think
there haven't any other better means since each Application's Application
Data are restriected by AppDomain boundary and can't be referencecd out
side the boudary. And I think your plan on checking the class's "AppClass"
field is considerable, you can define it as a public Property so that put
the checking code in "Get" method. Also, you may also consider initializing
the Application shared data when at start time in all the parts among the
server farm enviorment.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
C

cpnet

Ok, I'll try my approach then. What happens to a reference to something
that is across an AppDomain boundary? Does the reference get automatically
set to "null", or will I just get some sort of exception when I try to use
the reference? Ideally, .NET will just take care of setting the reference
to null for me so the only thing I have to check is if the private field
(that references the object that is now across an AppDomain) has become null
so I can take the proper action before returning the field through it's
public property.

Thanks,
cpnet
 
S

Steven Cheng[MSFT]

Hi Cpnet,

Thanks for your response. Yes, calling method on a invalid out of boudary
object reference will certianly cause exception. Anyway, provide the
protect when accessing such field is necessary. Good Luck!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top