页面载入中......
首页 联系我 返回顶部
Blog经过一次大的修整后
几个页面都采用了Cache机制,并设定了相应的过期时间
这样会加快页面的载入,减少等待的时间

但同时也有一个弊端:无法正确获取最新的记录
如发布一篇日志后,可能不会立即在首页显示出来,必须等缓存过期后,
才会再从数据库查询一次,此时才会看到最新的记录.

有时可能需要立即更新,这里就必须手工清除一下Cache
Cache类有一个Remove方法,但该方法需要提供一个CacheKey,但整个网站的CacheKey我们是无法得知的
只能经过遍历
protected void RemoveAllCache()
   {
      
      System.Web.Caching.Cache _cache = HttpRuntime.Cache;
      IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
      ArrayList al = new ArrayList();
      while (CacheEnum.MoveNext())
      {
         al.Add(CacheEnum.Key);
      }

      foreach (string key in al)
      {
         _cache.Remove(key);
      }
      show();
   }
//显示所有缓存
   void show()
   {
      string str = "";
      IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator();
      
      while (CacheEnum.MoveNext())
      {
         str += "缓存名<b>[" + CacheEnum.Key+"]</b><br />" ;
      }
      this.Label1.Text = "当前网站总缓存数:" + HttpRuntime.Cache.Count + "<br />"+str;
   }

2 Responses

收起评论
  1. 不惊鸟 九月 25 2006 , 13:09, #1
    不惊鸟
    首的样式怎么没有了
  2. 幻想曲 九月 25 2006 , 13:45, #2
    幻想曲
    可能在读取Cookie时有点问题

Write a comment:



(将显示你的Gravatar图标)  



[b][/b] - [i][/i] - [u][/u]- [quote][/quote]

:-/ ^_^ :d :o :kiss: :) :p :se: [yeah] :( :love: :han: :up: :cry: :zzz: o_o

暂时停止交换链接.

评论提交有问题?