Example: Implement static caching of dynamic web pages_PHP tutorial

WBOY
Release: 2016-07-13 10:04:40
Original
948 people have browsed it

Example: Implementing static caching of dynamic web pages

Source dynamic webpage

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span>Example: Implement static caching of dynamic web pages_PHP tutorial</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>Example: Implement static caching of dynamic web pages_PHP tutorial</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>
Copy after login

(Sample file:_samples/file_page.html)

Read cached static file information

<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>
Copy after login

Determine whether the static file exists

<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>
Copy after login
If

exists, cache is called; if it does not exist, page
is called.

<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>
Copy after login

Callable tag cache, read cache file

<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>
Copy after login

Callable tagspage

<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>
Copy after login

Introduce the dynamic web page file @{sys:curPath}file_page.html and save it as WEB-INF/cache/page_test.htmlFile

Show cached content

@{file:page}

Full code

<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>
Copy after login

Effect

Example: Implement static caching of dynamic web pages_PHP tutorial

(Sample file:_samples/file_cache.html)

Hurry up and experience it!



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/964931.htmlTechArticleExample: Implementing static caching of dynamic web pages Source dynamic web page title Example: Implementing static caching of dynamic web pages/title h3 Example : Implement static caching of dynamic web pages/h3 p chtml for e...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template