In my previous article "Page level caching with SqlDependency" you have learned how to create SqlDependency with page level Caching.
This article is intent to show you how to use Page.Cache class of System.Web.Caching.Cache with partial caching.
1. Partial Caching with no Dependency and Sliding Expiration with time
Partial caching means you are not going to cache the complete page only the part of page say userControl or some other control like Grid with large amount of data.
For eg: you have Grid to Bind with Dataset. So every time the page get refreshed or Grid get rebind to the data the data will come from database server every time. To prevent this round trip we can cache the DataSet.
Use the Cache object to insert the DataSet object into memory. Here is the Cache.Insert() static method explained with its options used. Here we use Time expiration with sliding expiration.
Cache.Insert(
/*name
of cache object*/"key",
/*Item
to be saved in Cache*/ds,
/*Dependency
*/null,
/*Expiration
Behavior*/
System.Web.Caching.Cache.NoAbsoluteExpiration,
/*Time span
to expire the cache*/
new
System.TimeSpan(0,0,30)
);
Retrieve the Cache object When a request come for DataSet.
DataSet ds
= (DataSet)Cache["key"];
// Check if Dataset was saved into Cache
Now check if
(ds == null) then perform your query to DataBase fetch the refresh data and add it to cache again.
Here is the complete code for Caching a DataSet into database.
protected void Page_Load(object sender, EventArgs
e)
{
DataSet
ds = null;
//Retrieve
the dataset using key from Cache.
ds = (DataSet)Cache["key"];
// Check if
Dataset was saved into Cache
if
(ds == null)

Gowtham RajamanickamPosted Apr 12, 2016, 1:17 AM
good
sagar BhosalePosted Feb 1, 2011, 12:59 AM
Thanks for uploading such nice tutorials. I want to know how to create Chatting application in browser? using simple asp.net concept without using socket & remoting concept.Please replye as you possible.