早期我们有一个程序,去保存浏览器缓存文件。后来我们直接改为去把网页上的图片COPY到windows剪切板里然后将图片保存到文件了,根本不读浏览器的缓存文件了!所以说,你的那个想法可能是很过时的了。

解决方案 »

  1.   

    将数据项从缓存中移除
    //判断缓存是否为空
     protected void Page_Load(object sender, EventArgs e)
        {
            if (Cache["UserName"] == null)
            {
                txtMsg.Text = "目前UserName缓存内容为:null";
            }//CodeGo.net/
        }
     //加入缓存
        protected void btnAddCache_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserName.Text))
            {
                Cache.Insert("UserName", txtUserName.Text);
                txtMsg.Text = "目前UserName缓存内容为:" + Cache["UserName"].ToString();
            }
        }
     //移除缓存
        protected void btnRemoveCache_Click(object sender, EventArgs e)
        {
            Cache.Remove("UserName");
        }
    ####如果缓存过期自动移除缓存
     //将数据项目加入缓存
        protected void btnAddCache_Click(object sender, EventArgs e)
        {
            //利用Cache.Add()方法将数据加入缓存
            //绝对过期(AbsoluteExpiration)
            Cache.Add("Name", txtUserName.Text, null, DateTime.Now.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            Cache.Add("Phone", txtTel.Text, null, DateTime.Now.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            Cache.Add("Position", txtJob.Text, null, DateTime.Now.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null);
            //弹性过期(SlidingExpiration)
            //Cache.Add("Name", txtUserName.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 1, 0), System.Web.Caching.CacheItemPriority.Default, null);
            //Cache.Add("Phone", txtTel.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 1, 10), System.Web.Caching.CacheItemPriority.Default, null);
            //Cache.Add("Position", txtJob.Text, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 1, 10), System.Web.Caching.CacheItemPriority.Default, null);
            txtMsg.Text = "缓存加入成功!";
        }