简单使用cache例子

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class newshow : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            shownews();
        }
    }
    private void shownews()
    {
        DataTable dt =new DataTable();
        if (Cache["ShowNews"] != null)
        {           
            dt =(DataTable) Cache.Get("ShowNews");           
        }
        else
        {
            int strwhere = 0;
            Cn1yw.BLL.Article bll = new Cn1yw.BLL.Article();
            DataSet ds = new DataSet();
            ds = bll.newshow(10, strwhere);
            dt = ds.Tables[0];
            Cache.Insert("ShowNews", dt, null, DateTime.Now.AddMinutes(720), TimeSpan.Zero);
        }

   }

}

posted @ 2008-09-01 20:26  郑希强  阅读(374)  评论(0编辑  收藏  举报