aspx页面的缓存功能自己定做

aspx页面的缓存功能自己定做
---------------------------------- 
.net里 aspx有缓存功能,在页面加入OutPutCache指示即可。 但是有个小缺点就是
时间固定了就不能改变了。(有谁知道请告诉我) 比如设置过期时间为10分钟。 那么
在这10分钟里,比如数据库里商品价格变了。 想立刻刷新这个页面的缓存。 难道要等到10分钟后才更新吗。 以下的例子可以实现。
---------------------------------- 
<%@ Page Language="C#" Debug="true" AutoEventWireup="true" %>
<%@Import Namespace="System" %>
<%@Import Namespace="System.Text" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Configuration" %>
<%@Import Namespace="System.Collections" %>
<%@Import Namespace="System.Web" %>
<%@Import Namespace="System.Web.Security" %>
<%@Import Namespace="System.Web.UI" %>
<%@Import Namespace="System.Web.UI.WebControls" %>
<%@Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@Import Namespace="System.Web.UI.HtmlControls" %>
<%@Import Namespace="System.Data.SqlClient" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
</title>
<meta http-equiv='Content-Type' content='text/html; charset=SJIS' />
</head>
<body>
    <form id="form1" method ="post" >
 <div id="headbox3">
     <% group_num = 2; %>
     <%for(int i=0;i<group_num;i++){ %>
         bbb<br />
     <% } %>
     
     <% = this.title %>
     <% = DateTime.Now.ToLongTimeString() %>
 </div>
</form>
</body>
</html>

<script language="C#" runat="server" >

 private string title = "kkkkkkkkkk";
 private int group_num = 0;
    //abcdefg
    protected void Page_Load(object sender, EventArgs e)
    {
        //System.Diagnostics.Debugger.Break();
        string strHtm = (string)System.Web.HttpContext.Current.Cache["strHtm"];
        bool goodsPriceChanged;
        goodsPriceChanged = false;
        if (strHtm != null && strHtm.Length > 1 && goodsPriceChanged==false)
        {
            Response.Write(strHtm);
            Response.End();
        }
    }
    protected void Page_PreRender(object sender, EventArgs e)
    {
        //System.Diagnostics.Debugger.Break();
        System.IO.TextWriter tw = new System.IO.StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(tw);
        Page.RenderControl(htw);
        string strHtm = htw.InnerWriter.ToString();
        //Cache.Insert("strHtm",strHtm ,null,DateTime.MaxValue,TimeSpan.FromSeconds(10));
        Cache.Insert("strHtm", strHtm, null, DateTime.Now.AddSeconds(5), Cache.NoSlidingExpiration);
    }

</script>

 

转载于:https://www.cnblogs.com/robotplayer/archive/2008/03/06/1093577.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值