[原]初次运用数据缓存机制

今天在书上看了数据缓存,就学着写了一个例子,留作以后参考,同时也欢迎各路高手路过时,教我一些更有难度的,呵呵!
CommonData data  =   new  CommonData(); //我自己写的一个类,用于取DataTable的
DataTable dt 
=   null ;
dt 
=  (DataTable)Context.Cache[ " JobParentCategory " ]; //Context.Cache -> System.Web
if  (dt  ==   null )
{
  dt 
=  data.JobParentCategory();
  Context.Cache.Insert(
" JobParentCategory " , dt); //把数据存入Cache中
}
foreach  (DataRow dr  in  dt.Rows) //如果dt不为空,就直接遍历Cache中的DataTable
{
  ddlJobCategory.Items.Add(
new  ListItem(dr[ 2 ].ToString(), dr[ 1 ].ToString()));
}

你可能感兴趣的:(缓存)