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
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