글
WEB/ASP.NET With C# 2007. 3. 13. 16:13HttpContext.Current.Cache의 사용..
//--> 캐쉬에서 가져오기 : 저장되어져 있는 cache가 있다면 ds에 그값을 저장한다.
ds = (DataSet) HttpContext.Current.Cache["cacheXXX"];
// 만약 저장된 cache가 없다면..
if (ds==null)
{
// DB에서 DataSet을 받는다.
ds = <-- DataSet을 실제로 받아서 넣는것임......!!!!!
if (ds.Tables[0].Rows.Count > 0)
{
// DB에 데이터가 있다면 받아온 데이터를 캐쉬에 Insert!!
HttpContext.Current.Cache.Insert("cacheXXX", ds, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
}
else
{
// 받아온 데이터가 없다면..
HttpContext.Current.Cache.Remove("cacheXXX");
//--> 데이터가 없다는 얘긴데, 말도 안되므로 캐쉬를 일단 제거해줌
// (빈캐쉬가 오랫동안 남지 않도록)
}
}
컨트롤.DataSource = ds;
컨트롤.DataBind();
ds = (DataSet) HttpContext.Current.Cache["cacheXXX"];
// 만약 저장된 cache가 없다면..
if (ds==null)
{
// DB에서 DataSet을 받는다.
ds = <-- DataSet을 실제로 받아서 넣는것임......!!!!!
if (ds.Tables[0].Rows.Count > 0)
{
// DB에 데이터가 있다면 받아온 데이터를 캐쉬에 Insert!!
HttpContext.Current.Cache.Insert("cacheXXX", ds, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
}
else
{
// 받아온 데이터가 없다면..
HttpContext.Current.Cache.Remove("cacheXXX");
//--> 데이터가 없다는 얘긴데, 말도 안되므로 캐쉬를 일단 제거해줌
// (빈캐쉬가 오랫동안 남지 않도록)
}
}
컨트롤.DataSource = ds;
컨트롤.DataBind();
RECENT COMMENT