Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Q: Initialising and updating a class with only static members & database dependency

Reply
Thread Tools

Q: Initialising and updating a class with only static members & database dependency

 
 
mark4asp
Guest
Posts: n/a
 
      07-05-2007
Q: Initialising and updating a class with only static members &
database dependency

I have a class with the following members:

public static List<ACIS> ACIS_List;

static AssetClass() { // blah }

public static ACIS Get_ACIS(string sACISCode) { // blah }

public static ACIS Get_ACIS(int iACIS_Id) { // blah }

Furthermore there are another 6 classes like this - each one has a
static List<T> with methods used to search the List<T> to return data.

Classes fall into 2 different types: (a) those with more or less
fixed, unchanging, data and (b) those having data which may change
daily.

Q1. What is the best way to initialise all these classes at once? I
would like to load all these classes with data at once because that
would only need one hit to the database.

Q2. Taking the reply to Q1 above into account, what is the best kind
of constructor to use? static, private, etc.? Should I be using the
constructor to load the class List<T> with data?

Q3. If some of these Lists become out-of-date, can I set up a
dependency which works to update the List<T> with the most recent data
- i.e. something which works like a cache dependency?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      07-05-2007
Probably the best way to initialize your classes all at once is to call a
method from your global.asax Application_Start handler that gets the data
from the database, and (however your operation works) makes some sort of
action on each static class that causes it to do whatever it does (for
example, excercize a static ctor).

Regarding having a dependency, you could certainly use a SQLCacheDependency
to call your method that you put into the Application_Start handler to
refresh your classes.

Not entirely sure whether having static classes is the answer here, though.
it might be better just to cache the stuff as instances and use the
SqlCacheDependency to invalidate the cached data.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com



"mark4asp" wrote:

> Q: Initialising and updating a class with only static members &
> database dependency
>
> I have a class with the following members:
>
> public static List<ACIS> ACIS_List;
>
> static AssetClass() { // blah }
>
> public static ACIS Get_ACIS(string sACISCode) { // blah }
>
> public static ACIS Get_ACIS(int iACIS_Id) { // blah }
>
> Furthermore there are another 6 classes like this - each one has a
> static List<T> with methods used to search the List<T> to return data.
>
> Classes fall into 2 different types: (a) those with more or less
> fixed, unchanging, data and (b) those having data which may change
> daily.
>
> Q1. What is the best way to initialise all these classes at once? I
> would like to load all these classes with data at once because that
> would only need one hit to the database.
>
> Q2. Taking the reply to Q1 above into account, what is the best kind
> of constructor to use? static, private, etc.? Should I be using the
> constructor to load the class List<T> with data?
>
> Q3. If some of these Lists become out-of-date, can I set up a
> dependency which works to update the List<T> with the most recent data
> - i.e. something which works like a cache dependency?
>
>

 
Reply With Quote
 
 
 
 
mark4asp
Guest
Posts: n/a
 
      07-05-2007
On 5 Jul, 15:54, Peter Bromberg [C# MVP]
<(E-Mail Removed)> wrote:
> Probably the best way to initialize your classes all at once is to call a
> method from your global.asax Application_Start handler that gets the data
> from the database, and (however your operation works) makes some sort of
> action on each static class that causes it to do whatever it does (for
> example, excercize a static ctor).
>
> Regarding having a dependency, you could certainly use a SQLCacheDependency
> to call your method that you put into the Application_Start handler to
> refresh your classes.
>
> Not entirely sure whether having static classes is the answer here, though.
> it might be better just to cache the stuff as instances and use the
> SqlCacheDependency to invalidate the cached data.
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> BlogMetaFinder(BETA): http://www.blogmetafinder.com
>
>
>
> "mark4asp" wrote:
> > Q: Initialising and updating a class with only static members &
> > database dependency

>
> > I have a class with the following members:

>
> > public static List<ACIS> ACIS_List;

>
> > static AssetClass() { // blah }

>
> > public static ACIS Get_ACIS(string sACISCode) { // blah }

>
> > public static ACIS Get_ACIS(int iACIS_Id) { // blah }

>
> > Furthermore there are another 6 classes like this - each one has a
> > static List<T> with methods used to search the List<T> to return data.

>
> > Classes fall into 2 different types: (a) those with more or less
> > fixed, unchanging, data and (b) those having data which may change
> > daily.

>
> > Q1. What is the best way to initialise all these classes at once? I
> > would like to load all these classes with data at once because that
> > would only need one hit to the database.

>
> > Q2. Taking the reply to Q1 above into account, what is the best kind
> > of constructor to use? static, private, etc.? Should I be using the
> > constructor to load the class List<T> with data?

>
> > Q3. If some of these Lists become out-of-date, can I set up a
> > dependency which works to update the List<T> with the most recent data
> > - i.e. something which works like a cache dependency?- Hide quoted text -

>
> - Show quoted text -


Thanks for the reply Peter. It may be easier to use the Cache but, it
seems to me, not the most efficient way to get things done. When I
want to access say a List<Manager> I must get the object from the
cache, cast it to List<Manager>, check to see whether it's null (then
possibly reload it from the database) before it's ready for use. This
is my dilema. Ease of using the cache against a slight overhead. I
shall try both solutions, but probably go with the one we know works
right now.

PS: I would be very nice if microsoft were to expand the database
dependencies so that objects not in the cache (such as my List<T>s)
could also be set to null when a database table is changed. (Microsoft
- Is anyone listening to me?)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
initialising static member with static methode Jens Henrik Goebbert C++ 3 10-31-2007 11:54 PM
Difference between static final members and final static members(if any)? JFCM Java 4 02-07-2006 11:32 AM
Extending a class - initialising new members. Fred C++ 6 10-26-2004 12:19 PM
Instantiating a static class( Class with all static members - methods and variables) SaravanaKumar Java 6 10-19-2004 08:20 AM
Initialising base class reference members from a derived class Tim Clacy C++ 3 03-04-2004 08:54 PM



Advertisments