源动态网页
- <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.html</file>
判断静态文件是否存在
- <if x="@{file:exists}"else=0>
- <call>page</call>
- <callxcallxcallxcallx=true>cache</call>
- </if>
存在就调用cache,不存在则调用page
- <call>page</call>
- <call x=true>cache</call>
可调用标签cache,读缓存文件
- <chtml onlycallid=cache>
- <file act=read method=str name=page>WEB-INF/cache/page_test.html</file>
- </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.html</file>
- <if x="@{file:exists}" else=0>
- <call>page</call>
- <call x=true>cache</call>
- </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.html</file>
- </chtml>@{file:page}
- </html>
效果
(例子文件:_samples/file_cache.html)
抓紧体验体验吧!
来源:51CTO
时间: 2024-09-27 01:47:19