<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[smarty缓存:smarty缓存Cache控制， php smarty 安装 、配置、使用 及缓存cache的配置使用 。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 17 Mar 2010 06:40:33 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：smarty自己也能实现cache，这块于nginx的cache模块不一样，它能实现一个页面某些地方（块）用上cache，有些用不上，实现灵活控制。<br/>一）<br/>框架里一般写成配置文件：<br/>./libraries/smarty/Smarty.class.php <br/>&nbsp;&nbsp;&nbsp;&nbsp;/**<br/>&nbsp;&nbsp;&nbsp;&nbsp; * This enables template caching.<br/>&nbsp;&nbsp;&nbsp;&nbsp; * &lt;ul&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&lt;li&gt;0 = no caching&lt;/li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&lt;li&gt;1 = use class cache_lifetime value&lt;/li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp;&lt;li&gt;2 = use cache_lifetime in cache file&lt;/li&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; * &lt;/ul&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp; * @var integer<br/>&nbsp;&nbsp;&nbsp;&nbsp; */<br/>&nbsp;&nbsp;&nbsp;&nbsp;var $caching&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;var $cache_dir&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;&#039;cache&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;var $cache_lifetime&nbsp;&nbsp;=&nbsp;&nbsp;3600;<br/>二）配置文件,只配置路径，而不配置caching 值，在初始化时决定：<br/>[codes=php]<br/>&lt;?php<br/>defined(&#039;SYS_PATH&#039;) OR die(&#039;No direct access allowed.&#039;);<br/><br/>return array (<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;templates_ext&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#039;html&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;template_path&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; APP_PATH. &#039;views/&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;cache_path&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; DATA_PATH. &#039;cache/smarty_cache/&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;compile_path&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; DATA_PATH. &#039;cache/smarty_compile/&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;configs_path&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; DATA_PATH. &#039;config/&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;left_delimiter&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&gt; &#039;&lt;{&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;right_delimiter&#039;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; &#039;}&gt;&#039;,<br/>);<br/><br/>[/codes]<br/>三）smarty 默认是不cache的<br/>./libraries/smarty/Smarty.class.php:&nbsp;&nbsp; <br/>[codes=php]<br/> var $caching&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&nbsp;&nbsp;0;<br/>[/codes]<br/><br/><br/>简单实例配置smarty摘录：<br/>php smarty 安装 、配置、使用 及缓存cache的配置使用 ：<br/>cache 使用：<br/>&nbsp;&nbsp;&nbsp;&nbsp;cache配置：<br/>&nbsp;&nbsp;&nbsp;&nbsp;$smarty-&gt;cache_dir = &quot;/caches/&quot;;&nbsp;&nbsp;//缓存目录&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;$smarty-&gt;caching = true;&nbsp;&nbsp;//开启缓存,为flase的时侯缓存无效&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;$smarty-&gt;cache_lifetime = 60;&nbsp;&nbsp;//缓存时间&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;cache清除和使用：<br/>$smarty-&gt;display(&#039;cache.tpl&#039;, cache_id); //创建带ID的缓存<br/>cache.tpl //模板文件<br/>$smarty-&gt;clear_all_cache(); //清除所有缓存<br/>$smarty-&gt;clear_cache(&#039;index.htm&#039;); //清除index.tpl的缓存<br/>$smarty-&gt;clear_cache(&#039;index.htm&#039;,cache_id); //清除指定id的缓存 <br/>marty 安装配置 说明：<br/>下载smarty解压 将libs目录&nbsp;&nbsp; copy到项目主目录下，至少建立如下如下文件夹：templates&nbsp;&nbsp;templates_c&nbsp;&nbsp;configs&nbsp;&nbsp;cache<br/>index.php<br/>&lt;?php<br/>&nbsp;&nbsp;&nbsp;&nbsp; include(&quot;libs/Smarty.class.php&quot;);<br/>&nbsp;&nbsp;$smarty = new Smarty;<br/>&nbsp;&nbsp;$smarty-&gt;template_dir = &#039;./templates/&#039;;<br/>&nbsp;&nbsp;$smarty-&gt;compile_dir&nbsp;&nbsp;= &#039;./templates_c/&#039;;<br/>&nbsp;&nbsp;$smarty-&gt;config_dir&nbsp;&nbsp; = &#039;./configs/&#039;;<br/>&nbsp;&nbsp;$smarty-&gt;cache_dir&nbsp;&nbsp;&nbsp;&nbsp;= &#039;./cache/&#039;;<br/>&nbsp;&nbsp;&nbsp;&nbsp; $smarty-&gt;caching&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= true;<br/>&nbsp;&nbsp;&nbsp;&nbsp; $smarty-&gt;cache_lifetime = 60;<br/>&nbsp;&nbsp;$smarty-&gt;left_delimiter = &quot;&lt;{&quot;;<br/>&nbsp;&nbsp;$smarty-&gt;right_delimiter = &quot;}&gt;&quot;;<br/>&nbsp;&nbsp;$smarty-&gt;assign(&quot;title&quot;, &quot;垃圾&quot;);<br/>&nbsp;&nbsp;$smarty-&gt;assign(&quot;content&quot;,&quot;测试用的网页内容00&quot;);<br/>&nbsp;&nbsp;$smarty-&gt;display(&quot;index.tpl&quot;,cache_id);<br/>&nbsp;&nbsp;?&gt;<br/>index.tpl模板文件<br/>&lt;html&gt;<br/>　　&lt;head&gt;<br/>　　&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;<br/>　　&lt;title&gt;&lt;{$title}&gt;&lt;/title&gt;<br/>　　&lt;/head&gt;<br/>　　&lt;body&gt;<br/>　　&lt;{$content}&gt;<br/>　　&lt;/body&gt;<br/>　　&lt;/html&gt;<br/><br/>摘自：http://blog.csdn.net/flyintheworldzdz/article/details/5557997<br/>____________________________smarty缓存Cache控制___________________________________<br/>　　smarty提供了强大缓存Cache功能但有时我们并不希望整篇文档都被缓存Cache而是有选择缓存<br/>Cache某部分内容或某部分内容不被缓存Cache例如你在页面上端使用个带有广告条位置模板广告条可以包含<br/>任何HTML、图象、FLASH等混合信息. 因此这里不能使用个静态链接同时我们也不希望该广告条被缓存Cache.<br/>这就需要在 insert 指定同时需要个取广告条内容信息smarty也提供了这种缓存Cache控制能力<br/>　　我们可以使用{insert}使模板部分不被缓存Cache<br/>　　可以使用$smarty-&gt;register_function($params,&amp;$smarty)阻止插件从缓存Cache中输出<br/>　　还可以使用$smarty-&gt;register_block($params,&amp;$smarty)使整篇页面中某块不被缓存Cache<br/>　　下面我们真对个简单需求分别介绍说明这 3种控制缓存Cache输出思路方法<br/>　　需求:被缓存Cache文档中当前时间不被缓存Cache随每次刷新而变化<br/>　　1、使用insert使模板部分不被缓存Cache<br/>　　index.tpl:<br/>　　&lt;div&gt;{insert name=&quot;get_current_time&quot;}&lt;/div&gt;<br/>　　index.php<br/>function insert_get_current_time{<br/>　　 　 date(&quot;Y-m-d H:m:s&quot;);<br/>}<br/>$smarty= smarty;<br/>$smarty-&gt;caching = true;<br/>(!$smarty-&gt;is_cached){<br/>　　 　.......<br/>}<br/>$smarty-&gt;display(&#039;index.tpl&#039;);<br/>　　注解:<br/>　　定义个名格式为:inser_name(.gif&#039; /&gt; $params, object &amp;$smarty),<br/>　　参数可选如果在模板insert思路方法中需要加入其他属性就会作为传递给用户定义<br/>　　如:{insert name=&#039;get_current_time&#039; local=&#039;zh&#039;}<br/>　　在get_current_time中我们就可以通过$params[&#039;local&#039;]来获得属性值<br/>　　如果在get_current_time中需要用到当前smarty对象思路方法或属性就可以通过第 2个参数获得<br/>　　这时你会发现index.tpl已被缓存Cache但当前时间却随每次刷新在不断变化<br/>　　2、使用register_function阻止插件从缓存Cache中输出<br/>　　index.tpl:<br/>&lt;div&gt;{current_time}{/div}<br/>index.php:<br/>function smarty_function_current_time($params, &amp;$smarty){<br/>　　 　 date(&quot;Y-m-d H:m:s&quot;);<br/>}<br/>$smarty= smarty;<br/>$smarty-&gt;caching = true;<br/>$smarty-&gt;register_function(&#039;current_time&#039;,&#039;smarty_function_current_time&#039;,false);<br/>(!$smarty-&gt;is_cached){<br/>　　 　.......<br/>}<br/>$smarty-&gt;display(&#039;index.tpl&#039;);<br/>　　注解:<br/>　　定义个名格式为:smarty_type_name($params, &amp;$smarty)<br/>　　type为function<br/>　　name为用户自定义标签名称在这里是{current_time}<br/>　　两个参数是必须即使在中没有使用也要写上两个参数功能同上<br/>　　3、使用register_block使整篇页面中某块不被缓存Cache<br/>　　index.tpl:<br/>&lt;div align=&#039;center&#039;&gt;<br/>Page created: {&quot;0&quot;&#124;date_format:&quot;%D %H:%M:%S&quot;}<br/>{dynamic}<br/>Now is: {&quot;0&quot;&#124;date_format:&quot;%D %H:%M:%S&quot;}<br/>... do other stuff ...<br/>{/dynamic}<br/>&lt;/div&gt;<br/>index.php:<br/>function smarty_block_dynamic($param, $content, &amp;$smarty) {<br/>$content;<br/>}<br/>$smarty = Smarty;<br/>$smarty-&gt;caching = true;<br/>$smarty-&gt;register_block(&#039;dynamic&#039;, &#039;smarty_block_dynamic&#039;, false);<br/>(!$smarty-&gt;is_cached){<br/>　　 　.......<br/>}<br/>$smarty-&gt;display(&#039;index.tpl&#039;);<br/>　　注解:<br/>　　定义个名格式为:smarty_type_name($params, &amp;$smarty)<br/>　　type为block<br/>　　name为用户自定义标签名称,在这里是{dynamic}<br/>　　两个参数是必须即使在中没有使用也要写上两个参数功能同上<br/>　　4、整理总结<br/>　　(1)对缓存Cache控制能力:<br/>　　使用register_function和register_block能够方便控制插件输出缓冲能力可以通过第 3个参数控制是否缓存<br/>Cache默认是缓存Cache需要我们显示设置为false正如我们试验中所做那样“$smarty-<br/>&gt;register_function(&#039;current_time&#039;,&#039;smarty_function_current_time&#039;,false);”<br/>　　但insert默认是不缓存Cache并且这个属性不能修改从这个意义上讲insert对缓存Cache控制能力似乎不如<br/>register_function和register_block强<br/>　　(2)使用方便性:<br/>　　但是insert使用非常方便不用显示注册只要在当前请求过程中包含这个smarty就会自动在当前请求过程中<br/>查找指定<br/>　　当然register_function也可以做到不在运行时显示注册但是那样做效果跟其他模版样统统被缓存Cache并<br/>且不能控制<br/>　　如果你使用在运行时显示register_function注册自定义那么定要在is_cached思路方法前完成注册工作<br/>　　否则在is_cached这步缓存Cache文档将找不到注册而导致smarty
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] smarty缓存:smarty缓存Cache控制， php smarty 安装 、配置、使用 及缓存cache的配置使用 。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>