Hi Raja123,
Actually Cache is not used for Performance but it avoid time delay of data fetching.
To get a data from database and store into cache means easily to get the data without go to server.
Here i am using web services for Cache.
//Namespace
using System.Web.Caching;
//Declare a Cache Object
Cache csEmpData;
string sData="Emp Details";
public DataTable GetDetails()
{
csEmpData=System.Web.HttpContext.Current.Cache;
if(csEmpData[sData] == null)
{
// Data Fetching Method from DataBase
DataTable dt = new DataTable(); // Here dt is Output Data
csEmpData.Insert(sData, (object)dt, null ,DateTime.Now.AddMinuutes(30), TimeSpan.Zero, CacheItemPriority.Default, null);
return (DataTable) (csEmpData[sData]);
}
else
{
return (DataTable) (csEmpData[sData]);
}
}
In this method i had set a time limit for cache is '30' minutes.So if i fetch the data with in 30 minutes, the data come from Cache object else its goes to database and then fetch the data.
Here i am give just basic idea only.
Refer this link its also helpful to you.
http://www.eggheadcafe.com/articles/20060407.asp
In my suggestion read more no.of articles.
Cheers :)
Thanks,
T.Saravanan
Raja123, if this helps please login to Mark As Answer. | Alert Moderator