在我的应用程序中,我尝试实现缓存(输出),但它无法正常工作, 也就是说,每次从缓存获取时,这都是我的代码。
<%@ OutputCache VaryByParam ="none" Location="Client" Duration="10" %>.
代码:
protected void btn_Click(object sender, EventArgs e)
{
DataView dtv;
dtv = (DataView)Cache["mycache"];
if(dtv ==null )
{
string sqry="select * from scrap";
da=new SqlDataAdapter (sqry,con);
ds=new DataSet();
da.Fill (ds);
dtv=new DataView (ds.Tables[0]);
Cache["mycache"]=dtv ;
Response.Write ("<script> alert ('from code')</script>");
}
else
{
Response.Write ("<script> alert ('from cache')</script>");
}
grd1 .DataSource =dtv;
grd1 .DataBind();
最佳答案
OutputCache和 Page.Cache
没有任何关系。 OutputCache 缓存页面生成的 html 并将其返回到浏览器,而无需再次运行代码(根据当前配置,持续 10 秒)。 Page.Cache
提供了一种存储应用程序范围数据的机制。一旦将某些内容添加到该缓存中,它就会一直存在,直到您下次重新启动网站为止(除非明确删除)。
关于c# - 在 asp.net 中缓存(输出)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2424340/