大家先看看我的思路对不对吧。假设设置缓存60分钟更新一次。
而且还要保证,用户输出缓存后能够即时显示,及时删除数据也能及时显示,总之就是对数据有操作就立即显示。
只不过,当其他用户访问的时候,如果数据没有更新或进行操作,就读取缓存内容。当用户操作数据就对之前的缓存删除并重新创建,当其他用户访问的时候(不更新数据的情况下)就直接读取缓存数据。如果这么操作是不是就没有必要设置60分钟更新一次了,直接一有数据操作就创建新的缓存并读取,否则就读取老的缓存。我是希望asp.net读取数据高效,并且用户能够及时看到更新的数据,大家有没有缓存的例子。

解决方案 »

  1.   

    设置duration就是一个“最长缓存时间”,并不妨碍“用户修改数据时即使清除缓存”。
      

  2.   

    OutputCache要求你设置Duration,那么就设置吧。而数据缓存则不需要,通常你也可以设置一个(例如60分钟的)slidingExpiration时间参数。
      

  3.   

    OutputCache中如果你不设置Duration后边的字符串值,应该会出现编译错误吧?!那就设置吧。
      

  4.   

    Ajax这个我明白,我想理解缓存的数据呈现问题。
      

  5.   

    哦,我就知道能把页面缓存给清零,设置response.Expries=0
      

  6.   

    <%@ OutputCache SqlDependency="" Duration="100" VaryByParam="id"%>数据库缓存依赖
     
      

  7.   

    web.config里面要加上配置 
    <cache> 
          <sqlCacheDependency   enabled= "true "   pollTime= "500 "> 
          <databases> 
          <add   name= "database1 " 
          connectionStringName= "MyDevDB "   /> 
          </databases> 
          </sqlCacheDependency> 
          </cache>   在页面上的outputCache中: 
        <%@   outputcache   duration= "5000 "   varybyparam= "None "   sqldependency= "database1:表名 "   %> 
      

  8.   

    随便举个例子吧。两个文件default.aspx、global.asax<%@ Page Language="C#" %><<%@ OutputCache Duration="3600" VaryByParam="*" VaryByCustom="方案1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        protected void Page_PreRender(object sender, EventArgs e)
        {
            this.Label1.DataBind();
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        如果文件c:\a.txt中包括字符sp,则清除缓存:
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <hr />
        <asp:Label ID="Label1" runat="server" Text="<%# DateTime.Now.ToString() %>" EnableViewState="false"></asp:Label>
        </form>
    </body>
    </html><%@ Application Language="C#" %>
    <script RunAt="server">    public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            if (custom == "方案1")
            {
                string file = "c:\\a.txt";
                if (System.IO.File.Exists(file) && System.IO.File.ReadAllText(file).Contains("sp"))
                    return DateTime.Now.Ticks.ToString();   //只要让返回值变动,就会让OutputCache清除。
            }
            return base.GetVaryByCustomString(context, custom);
        }
           
    </script>
      

  9.   

    http://www.cnblogs.com/allnen/archive/2008/12/19/1358128.html
      

  10.   

    介绍你看看msdn的sqlCacheDependency类
      

  11.   

    http://msdn.microsoft.com/zh-cn/library/e3w8402y%28v=VS.80%29.aspx