缓存

//当前时间
            string now=DateTime.Now.ToString();
            this.lbl1.Text=now;
            //绝对过期
            if(Cache["now"]==null)
            {
                Cache.Insert("now",now,null,DateTime.Now.AddSeconds(5),System.Web.Caching.Cache.NoSlidingExpiration);
                this.lbl2.Text=now;
            }
            else
            {
                this.lbl2.Text=Cache["now"].ToString();
            }
            //滑动过期
            if(Cache["now2"] == null)
            {
                Cache.Insert("now2", now, null,System.Web.Caching.Cache.NoAbsoluteExpiration,new TimeSpan(0,0,5));
                this.lbl3.Text = now;
            }
            else
            {
                this.lbl3.Text = Cache["now2"].ToString();
            }

原文地址:https://www.cnblogs.com/wangtiantian/p/5033078.html