better performance

A

Aaron

Some of my db-driven web pages rarely change. They pull the exact same data
every time (the table is almost read-only). Should I consider using page
caching? or do i just need to turn on caching in IIS 6? I'm new to this.
could someone point me to the right direction?

Thanks,
Aaron
 
J

Joshua Flanagan

If the data is only used on a single page, you could use page caching
(and it will definitely be better than no caching).
But if you are using the same "semi-static" data on multiple pages,
consider using the application-wide Cache. The same objects are
available from every page (as Page.Cache).
You can retrieve the data once from the database, add it to the cache
and then on subsequent pages, just retrieve the data from the cache.

Quick code (not guaranteed to compile as-is, read the documentation):

Page_Load(){
// try to retrieve data from cache
DataSet myData = Cache["MyDataKey"] as DataSet;

if (myData == null){
// data was not in cache, retrieve from database
myData = LoadDataSetFromDatabase();
this.Cache.Insert("MyDataKey", myData);
}

// use myData
}

The different overloads of Cache.Insert() allow you to specify different
rules for how long the data should stay in the cache.


Joshua Flanagan
http://flimflan.com/blog
 
K

Kevin Spencer

Good question, Aaron.

Note that you have said that "some of my... pages rarely change." This
brings up the question of whether these pages may use the same data as
others. That is, Page-caching is useful if the data is only used by one
page. However, if the data is used by more than one page, you're looking at
a different caching mechanism, such as Application Cache (if the data is
used by all user clients on more than one page), or Session (if the data is
used only by one user client on more than one page).

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 
A

Aaron

Thanks for your replies.

Is there anything I can do in the database design to optimize for this as
well?

db table example: only 2 columns

ID | LONGTEXT
1 | some ...
2 | text ...
3 | here ....
 
K

Kevin Spencer

Base on what you told me, no. It looks pretty straightforward. You might use
a Stored Procedure, rather then sending a SQL query, and get a slight boost.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Sometimes you eat the elephant.
Sometimes the elephant eats you.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top