Thursday, April 10, 2008

Caching data -fast performance

public class CacheSearch
{
protected DataSet _ds;
protected string ksearch;

public CacheSearch()
{
}

public static DataSet GetAlldataCIdKeyid(int cid, int kid)
{
return GetAlldataCityIdKeyid(HttpContext.Current, cid, kid);
}
protected static DataSet GetAlldataCityIdKeyid(HttpContext context, int cid, int kid)
{
string ksearchkey = “cachkey_” + cid.ToString() + “_” + kid.ToString();
DateTime expiration = DateTime.Now.AddMinutes(10);
DataSet allcidkey = context.Cache[ksearchkey] as DataSet;
if (allcidkey == null)
{
allcidkey = KEYWORDSEARCH.keysearchcidkeyid(cid, kid);
context.Cache.Add(ksearchkey, allcidkey, null, expiration, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);

}
return allcidkey;
}

}



public class KEYWORDSEARCH
{
public static DataSet keysearchcidkeyid(int cid, int keyid)
{
DATALAYER dl = new DATALAYER();
dl.AddParameter(”@cid”, cid);
dl.AddParameter(”@kid”, keyid);
return dl.ExecuteDataSet(”getkeysearch”);
}
}

and codehind of page u write code which bind to datagrid
DataSet ds = CacheSearch.GetAlldataCIdKeyid(cid,kid);

this ds bind with datagrid and show better performance



here Datalayer is connection class if u want to according ur need u change

No comments :

Post a Comment

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath