1.页面缓存
在xx.aspx头文件中加入:
<%@ OutputCache Duration="10" VaryByParam="none"%>
其中Duration为持续时间,单位为秒
2.文件依赖缓存
using System;
using System.Web;
using System.Web.Caching;
protected void ShowTime()
{
//键
string key = "TimeNow";
//试图从缓存中获取时间
string strTime = (string)HttpRuntime.Cache[key];
if (string.IsNullOrEmpty(strTime))
{
strTime = DateTime.Now.ToString();
//新建缓存依赖
CacheDependency dep=
new CacheDependency(Server.MapPath("~/myCacheDependency.htm"),DateTime.Now);
//插入缓存
Cache.Insert(key, strTime, dep);
}
Label1.Text = strTime;
}
3.SQL缓存依赖
未完待续