实例:实现动态网页的静态缓存
程序员文章站
2022-06-11 19:50:26
...
实例:实现动态网页的静态缓存
源动态网页
- title>实例:实现动态网页的静态缓存title>
- h3>实例:实现动态网页的静态缓存h3>
- p>
- chtml>
- for end=0 start=20>
- b>@{int:@{for:getSuffix}+1}-b>
- forendforendforendforend=@{for:getSuffix}>
- fontcolorfontcolorfontcolorfontcolor=red>@{int:@{for:getSuffix}+1}-font>
- for>
- br>
- for>
- chtml>
- p>
(例子文件:_samples/file_page.html)
读缓存的静态文件信息
- file act=info>WEB-INF/cache/page_test.htmlfile>
判断静态文件是否存在
- if x="@{file:exists}"else=0>
- call>pagecall>
- callxcallxcallxcallx=true>cachecall>
- if>
存在就调用cache,不存在则调用page
- call>pagecall>
- call x=true>cachecall>
可调用标签cache,读缓存文件
- chtml onlycallid=cache>
- file act=read method=str name=page>WEB-INF/cache/page_test.htmlfile>
- chtml>
可调用标签page
- chtml id=page file="@{sys:curPath}file_page.html" save="WEB-INF/cache/page_test.html" onlycall />
引入动态网页文件@{sys:curPath}file_page.html,并保存为WEB-INF/cache/page_test.html文件
显示缓存内容
@{file:page}
完整代码
- html>
- chtml>
- file act=info>WEB-INF/cache/page_test.htmlfile>
- if x="@{file:exists}" else=0>
- call>pagecall>
- call x=true>cachecall>
- if>
- chtml>
- chtml id=page file="@{sys:curPath}file_page.html" save="WEB-INF/cache/page_test.html" onlycall />
- chtml onlycall id=cache>
- file act=read method=str name=page>WEB-INF/cache/page_test.htmlfile>
- chtml>@{file:page}
- html>
效果
(例子文件:_samples/file_cache.html)
抓紧体验体验吧!
下一篇: PHP 已经成熟_PHP教程