Class design - minimize DB calls

H

H Branyan

I have a User class that takes a UserID as a parameter in the constructor,
and then looks up the record in the DB and stores the values into the User
class properties. Often when a page loads, I have to grab the same User
several times to display information on several different places on the
page.

In order to minimize the connections to the database when its the same User,
in this instance, I'd like for my User class to store Users as they are
created into some object that is Cached. When the User constructor is
called, it would check this Cache object and then use the Cached data in the
properties, rather than make a call to the database.

I am thinking of using Hashtable, with the UserId as the key, and the User
object for the Userid as the value. But this approach seems rather awkward.
Does anyone have ideas or suggestions? I would appreciate your input.

Thanks
 
G

George Ter-Saakov

If you need to keep some infor during the lifetime of one request use
HttpContext.Current.Items

George.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top