<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>幻想曲.Net &#187; cache</title>
	<atom:link href="http://yibin.us/tag/cache/feed" rel="self" type="application/rss+xml" />
	<link>http://yibin.us</link>
	<description>曾经沧海难为水，除却巫山不是云</description>
	<lastBuildDate>Tue, 15 May 2012 14:31:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Blog中的Cache应用</title>
		<link>http://yibin.us/archives/5574</link>
		<comments>http://yibin.us/archives/5574#comments</comments>
		<pubDate>Thu, 19 Oct 2006 01:50:00 +0000</pubDate>
		<dc:creator>幻想曲</dc:creator>
				<category><![CDATA[Develop]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://yibin.us/?p=5574</guid>
		<description><![CDATA[Blog昨天已给一份下一秒，并在本地调试成功。 通过我在本地做的NUnit测试，表明未出现程序上的错误。 Blog的主要页面均做了5分钟的Cache，所以大家现在看到的内容未必就是最新的。 Blog在朋友的一台服务器上，放在这里的目的主要用来做一个测试。因为前段时间放在剣气那里，一直出错，而且基本上都是SqlException异常，但实际上，blog里未涉及到大量、复杂的数据查询，而且在代码编写上，基本上都是安全的。 刚进后台看了一下站点的所有缓存 &#160; 当前共有18个缓存项，上服务器看到blog所在的w3wp占用内存52M，这是使用缓存的结果。 过二天去掉所有缓存项，实时从数据库查询，再来看看内存占用情况。]]></description>
			<content:encoded><![CDATA[<div>Blog昨天已给一份<a style="FONT-WEIGHT: bold; BACKGROUND-COLOR: #ffff00" href="http://www.saytd.com" target=_blank align>下一秒</a>，并在本地调试成功。</div>
<div>通过我在本地做的NUnit测试，表明未出现程序上的错误。</div>
<div>Blog的主要页面均做了5分钟的Cache，所以大家现在看到的内容未必就是最新的。</div>
<div>Blog在朋友的一台服务器上，放在这里的目的主要用来做一个测试。因为前段时间放在<a style="BACKGROUND-COLOR: #ffff00" href="http://zxsv.com" target=_blank>剣气</a>那里，一直出错，而且基本上都是SqlException异常，但实际上，blog里未涉及到大量、复杂的数据查询，而且在代码编写上，基本上都是安全的。</div>
<div>刚进后台看了一下站点的所有缓存</div>
<div><img alt="" hspace=5 src="/zh-cn/uploads/Snap1.gif" align=baseline border=0></div>
<div>&nbsp;</div>
<div>当前共有18个缓存项，上服务器看到blog所在的w3wp占用内存52M，这是使用缓存的结果。</div>
<div>过二天去掉所有缓存项，实时从数据库查询，再来看看内存占用情况。</div>
]]></content:encoded>
			<wfw:commentRss>http://yibin.us/archives/5574/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>列出当前站点所有Cache并清除</title>
		<link>http://yibin.us/archives/5552</link>
		<comments>http://yibin.us/archives/5552#comments</comments>
		<pubDate>Mon, 25 Sep 2006 03:40:00 +0000</pubDate>
		<dc:creator>幻想曲</dc:creator>
				<category><![CDATA[Develop]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://yibin.us/?p=5552</guid>
		<description><![CDATA[Blog经过一次大的修整后几个页面都采用了Cache机制,并设定了相应的过期时间这样会加快页面的载入,减少等待的时间 但同时也有一个弊端:无法正确获取最新的记录如发布一篇日志后,可能不会立即在首页显示出来,必须等缓存过期后,才会再从数据库查询一次,此时才会看到最新的记录. 有时可能需要立即更新,这里就必须手工清除一下CacheCache类有一个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 += "缓存名&#60;b&#62;[" + CacheEnum.Key+"]&#60;/b&#62;&#60;br [...]]]></description>
			<content:encoded><![CDATA[<p>Blog经过一次大的修整后<br />几个页面都采用了Cache机制,并设定了相应的过期时间<br />这样会加快页面的载入,减少等待的时间</p>
<p>但同时也有一个弊端:无法正确获取最新的记录<br />如发布一篇日志后,可能不会立即在首页显示出来,必须等缓存过期后,<br />才会再从数据库查询一次,此时才会看到最新的记录.</p>
<p>有时可能需要立即更新,这里就必须手工清除一下Cache<br />Cache类有一个Remove方法,但该方法需要提供一个CacheKey,但整个网站的CacheKey我们是无法得知的<br />只能经过遍历<br /><code><br />
protected void RemoveAllCache()<br />
   {</p>
<p>      System.Web.Caching.Cache _cache = HttpRuntime.Cache;<br />
      IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();<br />
      ArrayList al = new ArrayList();<br />
      while (CacheEnum.MoveNext())<br />
      {<br />
         al.Add(CacheEnum.Key);<br />
      }</p>
<p>      foreach (string key in al)<br />
      {<br />
         _cache.Remove(key);<br />
      }<br />
      show();<br />
   }<br />
//显示所有缓存<br />
   void show()<br />
   {<br />
      string str = "";<br />
      IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator();</p>
<p>      while (CacheEnum.MoveNext())<br />
      {<br />
         str += "缓存名&lt;b&gt;[" + CacheEnum.Key+"]&lt;/b&gt;&lt;br /&gt;" ;<br />
      }<br />
      this.Label1.Text = "当前网站总缓存数:" + HttpRuntime.Cache.Count + "&lt;br /&gt;"+str;<br />
   }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://yibin.us/archives/5552/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>对Cache的疑问</title>
		<link>http://yibin.us/archives/5538</link>
		<comments>http://yibin.us/archives/5538#comments</comments>
		<pubDate>Wed, 06 Sep 2006 04:43:00 +0000</pubDate>
		<dc:creator>幻想曲</dc:creator>
				<category><![CDATA[Develop]]></category>
		<category><![CDATA[cache]]></category>

		<guid isPermaLink="false">http://yibin.us/?p=5538</guid>
		<description><![CDATA[Blog的首页用的是一个Repeater DataSource来自一个类的某个方法,返回的是一个DataTable default页面没有做任何的Cache 直接将Repeater绑定到该DataTable然后进行显示 但这样一来在处理一些特殊日志时不大方便,如“隐藏日志” 于是创建一个List泛类型,遍历该DataTable,依次创建一个Document的实体,Add至List中,进行Cache 但实际运行效率却不如做Cache之前的效率 这个问题发生在哪里? 是对List的操作上吗?]]></description>
			<content:encoded><![CDATA[<p>Blog的首页用的是一个Repeater<br />
DataSource来自一个类的某个方法,返回的是一个DataTable<br />
default页面没有做任何的Cache<br />
直接将Repeater绑定到该DataTable然后进行显示<br />
但这样一来在处理一些特殊日志时不大方便,如“隐藏日志”</p>
<p>于是创建一个List<T>泛类型,遍历该DataTable,依次创建一个Document的实体,Add至List<T>中,进行Cache</p>
<p>string _cachekey = &quot;dv_&quot; + _pagesize.ToString();<br />
          if (Cache[_cachekey] == null)<br />
        {</p>
<p>            List&lt;Blog.Model.documents.documents&gt; list = new List&lt;Blog.Model.documents.documents&gt;();<br />
            if (dv.Rows.Count &gt; 0)<br />
            {<br />
                for (int i = 0; i &lt; dv.Rows.Count; i++)<br />
                {<br />
                    Blog.Model.documents.documents doc = new Blog.Model.documents.documents();<br />
                    doc.author = dv.Rows[i][&quot;author&quot;].ToString();<br />
                    doc.CateGoryID = (int)dv.Rows[i][&quot;CateGoryID&quot;];<br />
                    doc.CategoryName = dv.Rows[i][&quot;CategoryName&quot;].ToString();<br />
                    doc.commont = &quot;&quot;;<br />
                    doc.content = dv.Rows[i][&quot;content&quot;].ToString();<br />
                    doc.documentid = (int)dv.Rows[i][&quot;documentid&quot;];<br />
                    doc.DocumentType = &quot;&quot;;<br />
                    doc.editor = &quot;&quot;;<br />
                    doc.EnableComment = (bool)dv.Rows[i][&quot;enablecomment&quot;];<br />
                    doc.FilePath = &quot;&quot;;<br />
                    doc.guid = &quot;&quot;;<br />
                    doc.hit = (int)dv.Rows[i][&quot;hit&quot;];<br />
                    doc.Iscommend = (bool)dv.Rows[i][&quot;Iscommend&quot;];<br />
                    doc.IsTop = (bool)dv.Rows[i][&quot;istop&quot;];<br />
                    doc.keyword = &quot;&quot;;<br />
                    doc.PublishDate = (DateTime)dv.Rows[i][&quot;PublishDate&quot;];<br />
                    doc.source = &quot;&quot;;<br />
                    doc.subject = dv.Rows[i][&quot;subject&quot;].ToString();<br />
                    doc.Tags = global.getTagsByDocumentid(doc.documentid);<br />
                    doc.url = &quot;&quot;;<br />
                    doc.IsPublish = (bool)dv.Rows[i][&quot;ispublish&quot;];<br />
                    if (doc.IsPublish == false)<br />
                    {<br />
                        doc.subject = &quot;隐藏日志或草稿&quot;;<br />
                        doc.content = &quot;隐藏日志或草稿,暂时无法查看!&quot;;<br />
                    }<br />
                    list.Add(doc);<br />
                }<br />
            }<br />
            Cache.Insert(_cachekey, list, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);<br />
        }</p>
<p>        _rep_body.DataSource = (List&lt; Blog.Model.documents.documents&gt;)Cache[_cachekey];<br />
        _rep_body.DataBind();</p>
<p>但实际运行效率却不如做Cache之前的效率<br />
这个问题发生在哪里?<br />
是对List的操作上吗?</p>
]]></content:encoded>
			<wfw:commentRss>http://yibin.us/archives/5538/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

