实例:实现动态网页的静态缓存_PHP教程

WBOY
发布: 2016-07-13 10:04:40
原创
939 人浏览过

实例:实现动态网页的静态缓存

 源动态网页

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span>实例:实现动态网页的静态缓存</span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">h3</span><span class="tag">></span><span>实例:实现动态网页的静态缓存</span><span class="tag"></</span><span class="tag-name">h3</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">p</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">chtml</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">for</span><span> </span><span class="attribute">end</span><span>=</span><span class="attribute-value">0</span><span> </span><span class="attribute">start</span><span>=</span><span class="attribute-value">20</span><span class="tag">></span><span>   </span></span></li><li><span>    <span class="tag"><</span><span class="tag-name">b</span><span class="tag">></span><span>@{int:@{for:getSuffix}+1}-</span><span class="tag"></</span><span class="tag-name">b</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span>    <span class="tag"><</span><span class="tag-name">forendforend</span><span class="attribute">forendforend</span><span>=@{for:getSuffix}</span><span class="tag">></span><span>   </span></span></li><li><span>        <span class="tag"><</span><span class="tag-name">fontcolorfontcolor</span><span class="attribute">fontcolorfontcolor</span><span>=</span><span class="attribute-value">red</span><span class="tag">></span><span>@{int:@{for:getSuffix}+1}-</span><span class="tag"></</span><span class="tag-name">font</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span>    <span class="tag"></</span><span class="tag-name">for</span><span class="tag">></span><span>   </span></span></li><li><span>    <span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"></</span><span class="tag-name">for</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"></</span><span class="tag-name">chtml</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"></</span><span class="tag-name">p</span><span class="tag">></span><span>   </span></span></li></ol>
登录后复制

(例子文件:_samples/file_page.html)

读缓存的静态文件信息

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">file</span><span> </span><span class="attribute">act</span><span>=</span><span class="attribute-value">info</span><span class="tag">></span><span>WEB-INF/cache/page_test.html</span><span class="tag"></</span><span class="tag-name">file</span><span class="tag">></span><span>  </span></span></li></ol>
登录后复制

判断静态文件是否存在

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">if</span><span> </span><span class="attribute">x</span><span>="@{file:exists}"</span><span class="attribute-value">else</span><span>=0</span><span class="tag">></span><span>   </span></span></li><li><span>    <span class="tag"><</span><span class="tag-name">call</span><span class="tag">></span><span>page</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span>    <span class="tag"><</span><span class="tag-name">callxcallx</span><span class="attribute">callxcallx</span><span>=</span><span class="attribute-value">true</span><span class="tag">></span><span>cache</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"></</span><span class="tag-name">if</span><span class="tag">></span><span>   </span></span></li></ol>
登录后复制

存在就调用cache,不存在则调用page

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">call</span><span class="tag">></span><span>page</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li><li><span> <span class="tag"><</span><span class="tag-name">call</span><span> </span><span class="attribute">x</span><span>=</span><span class="attribute-value">true</span><span class="tag">></span><span>cache</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li></ol>
登录后复制

可调用标签cache,读缓存文件

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">chtml</span><span> </span><span class="attribute">onlycallid</span><span>=</span><span class="attribute-value">cache</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">file</span><span> </span><span class="attribute">act</span><span>=</span><span class="attribute-value">read</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">str</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">page</span><span class="tag">></span><span>WEB-INF/cache/page_test.html</span><span class="tag"></</span><span class="tag-name">file</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"></</span><span class="tag-name">chtml</span><span class="tag">></span><span>   </span></span></li></ol>
登录后复制

可调用标签page

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">chtml</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">page</span><span> </span><span class="attribute">file</span><span>=</span><span class="attribute-value">"@{sys:curPath}file_page.html"</span><span> </span><span class="attribute">save</span><span>=</span><span class="attribute-value">"WEB-INF/cache/page_test.html"</span><span> onlycall </span><span class="tag">/></span><span>   </span></span></li></ol>
登录后复制

引入动态网页文件@{sys:curPath}file_page.html,并保存为WEB-INF/cache/page_test.html文件

显示缓存内容

@{file:page}

完整代码

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">html</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">chtml</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">file</span><span> </span><span class="attribute">act</span><span>=</span><span class="attribute-value">info</span><span class="tag">></span><span>WEB-INF/cache/page_test.html</span><span class="tag"></</span><span class="tag-name">file</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">if</span><span> </span><span class="attribute">x</span><span>=</span><span class="attribute-value">"@{file:exists}"</span><span> </span><span class="attribute">else</span><span>=</span><span class="attribute-value">0</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span>    <span class="tag"><</span><span class="tag-name">call</span><span class="tag">></span><span>page</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li><li><span>    <span class="tag"><</span><span class="tag-name">call</span><span> </span><span class="attribute">x</span><span>=</span><span class="attribute-value">true</span><span class="tag">></span><span>cache</span><span class="tag"></</span><span class="tag-name">call</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"></</span><span class="tag-name">if</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"></</span><span class="tag-name">chtml</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">chtml</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">page</span><span> </span><span class="attribute">file</span><span>=</span><span class="attribute-value">"@{sys:curPath}file_page.html"</span><span> </span><span class="attribute">save</span><span>=</span><span class="attribute-value">"WEB-INF/cache/page_test.html"</span><span> onlycall </span><span class="tag">/></span><span>   </span></span></li><li><span><span class="tag"><</span><span class="tag-name">chtml</span><span> onlycall </span><span class="attribute">id</span><span>=</span><span class="attribute-value">cache</span><span class="tag">></span><span>   </span></span></li><li class="alt"><span><span class="tag"><</span><span class="tag-name">file</span><span> </span><span class="attribute">act</span><span>=</span><span class="attribute-value">read</span><span> </span><span class="attribute">method</span><span>=</span><span class="attribute-value">str</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">page</span><span class="tag">></span><span>WEB-INF/cache/page_test.html</span><span class="tag"></</span><span class="tag-name">file</span><span class="tag">></span><span>   </span></span></li><li><span><span class="tag"></</span><span class="tag-name">chtml</span><span class="tag">></span><span>@{file:page}   </span></span></li><li class="alt"><span><span class="tag"></</span><span class="tag-name">html</span><span class="tag">></span><span>   </span></span></li></ol>
登录后复制

效果

实例:实现动态网页的静态缓存

(例子文件:_samples/file_cache.html)

抓紧体验体验吧!



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/964931.htmlTechArticle实例:实现动态网页的静态缓存 源动态网页 title 实例:实现动态网页的静态缓存 / title h3 实例:实现动态网页的静态缓存 / h3 p chtml for e...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板