<?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>臭皮匠 &#187; cache</title>
	<atom:link href="http://guogoul.com/tag/cache/feed/" rel="self" type="application/rss+xml" />
	<link>http://guogoul.com</link>
	<description></description>
	<lastBuildDate>Fri, 29 Oct 2010 00:24:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>smarty局部页面缓存</title>
		<link>http://guogoul.com/2008/08/03/smarty_1/</link>
		<comments>http://guogoul.com/2008/08/03/smarty_1/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 13:59:34 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[smarty]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.guogoul.com/2008/08/03/smarty_1/</guid>
		<description><![CDATA[web2.0网站速度优化的最好方案是减少数据库访问.
缓存是减少数据库访问的最佳方案.
有两种最基本缓存的方式
1.页面缓存
1.1 如果你用的是smarty做为ui模板的话.页面缓存十分的方便
require(&#8217;Smarty.class.php&#8217;);
$smarty = new Smarty;
$smarty-&#62;caching = 1;
if(!$smarty-&#62;is_cached(&#8217;index.tpl&#8217;)) {
    // No cache available, do variable assignments here.
    $contents = get_database_contents();
    $smarty-&#62;assign($contents);
}
$smarty-&#62;display(&#8217;index.tpl&#8217;);
以上为最基本的缓存方案,对于同一个tpl,根据不同的参数可以缓存多个.
$smarty-&#62;is_cached(&#8217;index.tpl&#8217;,params); //根据参数判断
$smarty-&#62;display(&#8217;index.tpl&#8217; ,params);//根据参数显示
以上实现了整个页面的缓存
很多时候为了优化用户的体验,需要对局部即时显示.最方便的方案是对即时显示的部分做一下块标记.每次刷新时重新显示些块就可
index.php:
caching = 1;
function smarty_block_dynamic($param, $content, &#38;$smarty) {
    return $content;
}
$smarty-&#62;register_block(&#8217;dynamic&#8217;, &#8217;smarty_block_dynamic&#8217;, false);
$smarty-&#62;display(&#8217;index.tpl&#8217;);
?&#62;
index.tpl is:
Page created: {&#8217;0&#8242;&#124;date_format:&#8217;%D %H:%M:%S&#8217;}
{dynamic}
Now is: {&#8217;0&#8242;&#124;date_format:&#8217;%D %H:%M:%S&#8217;}
&#8230; do other stuff &#8230;
{/dynamic}
官方介绍
1.2: [...]]]></description>
		<wfw:commentRss>http://guogoul.com/2008/08/03/smarty_1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

