您的位置:首页 > 其它

cache缓存(未完成)

2016-11-30 17:30 204 查看
缓存html页面(后台代码就不走了)

    Duration="5"(缓存过期时间,单位:s)

    VaryByParam="*"(传递的是Url参数,防止缓存霍乱,可以为id,none,a)

<%@ OutputCache Duration="5" VaryByParam="*" %>


缓存依赖项,直接上Demo

protected void Page_Load(object sender, EventArgs e)
{
string fielPath = Request.MapPath("File.txt");
if (Cache["fileContent"]==null)
{
//文件缓存依赖
CacheDependency cDep=new CacheDependency(fielPath);
string fileContent = File.ReadAllText(fielPath);
Cache.Insert("fileContent", fileContent, cDep);
Response.Write("数据来自文件");
}
else
{
Response.Write("数据来自缓存" + Cache["fileContent"].ToString());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: