Heim > Backend-Entwicklung > PHP-Tutorial > 实例:实现动态网页的静态缓存_PHP教程

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

WBOY
Freigeben: 2016-07-13 10:04:40
Original
953 Leute haben es durchsucht

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

 源动态网页

<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>
Nach dem Login kopieren

(例子文件:_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>
Nach dem Login kopieren

判断静态文件是否存在

<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>
Nach dem Login kopieren

存在就调用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>
Nach dem Login kopieren

可调用标签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>
Nach dem Login kopieren

可调用标签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>
Nach dem Login kopieren

引入动态网页文件@{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>
Nach dem Login kopieren

效果

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

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

抓紧体验体验吧!



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/964931.htmlTechArticle实例:实现动态网页的静态缓存 源动态网页 title 实例:实现动态网页的静态缓存 / title h3 实例:实现动态网页的静态缓存 / h3 p chtml for e...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage