class - How to cache my static variables in asp.net -
my regular programs basicly started main() , first statement always:
main() { appsettings.initialize(); //etc. }
in asp.net program, want use same classes don't have main() use global.asax
application_beginrequest() { appsettings.initialize(); //etc. } application_start() { appsettings.initialize(); //etc. }
this way can keep on using global static variables appglobal.id, etc. use same classes , helper classes in wp7 , it's working fine , don't care initial startup of application variables in appglobal, appsettings take 2 seconds setup.
in asp.net doesn't work way because initialize/setup repeated every page request. cache appglobal class , appsettings class how?
extra edit of topic explain better problem:
because first page use appglobal.name variable in page code, added application_beginrequest.
public class appsettings { // public static void initialize() { } static appsettings() { appglobal.developermode = convert.toboolean(appconfigvalue("developermode,false")); appglobal.debuglevel = convert.toint32(appconfigvalue("debuglevel,1")); appglobal.filesfolder = appconfigvalue("filesfolder,files"); appglobal.logfilesfolder = appconfigvalue("logfilesfolder,logfiles"); appglobal.companyname = appconfigvalue("companyname"); appglobal.ownername = appconfigvalue("ownername"); appglobal.applicationid = ""; appglobal.initialize(); } } public class appglobal { public static bool developermode; public static int debuglevel = 0; public static string applicationname = ""; private static bool _initialized; public static void initialize() { } appglobal() { //initialize application (check license, setup folder names, settings) //this takes few seconds create } } public class log { public static string filename; public static int debuglevel = 0; public static bool initialized = false; static log() { filename = appglobal.applicationname; } //etc... }
it better make properties of variable , set , session variables although can cache class making serialized
try this:
myclass obj_cl = new myclass(); //do work session["obj_cl"] = obj_cl; //on retreival myclass tempobj = (myclass)session["obj_cl"];
Comments
Post a Comment