5ucms论坛
标题:
10、POPASP快速入门第十课 缓存技术
[打印本页]
作者:
admin
时间:
2019-4-1 16:33
标题:
10、POPASP快速入门第十课 缓存技术
cache.asp
<!--#include file="./popasp_inc.asp"-->
<%
Call A_("Index/cache")
dim key,item
%>
<html>
<head>
<title>数据缓存</title>
</head>
<body>
<p>
缓存时间:<br />
<%=V_("cache_time")%>
</p>
<p>
当前时间:<br />
<%=V_("now_time")%>
</p>
</body>
</html>
复制代码
IndexAction.class.asp
<%
' 本类由系统自动生成,仅供测试用途
Class IndexAction
public Sub index()
dim rs , range , page
'通过数据模型从数据库中取出一条记录
'set rs = M_("post").db.where(5).field("id,title").find()
'var_export rs
if that.get("page") = "" then
page = 1
else
page = that.get("page")
end if
if that.expired( "index" , page ) then
set rs = M_("post").db.page( array(null,10) ).field("id,title,add_time").select()
that.assign "page",P_("PAGE")(rs).show()
that.assign "list",array(rs)
that.cache '缓存的是整个该情况页,所以不需要else,自动显示缓存结果
end if
end Sub
public sub post
dim id
'that.get是request.querystring的一种简写
id = that.get("id")
if that.expired("post",id) then
set rs = M_("post").db.field("id,title,add_time,content").where(id).find()
that.assign "row",rs
that.cache
end if
end sub
sub cache
'var_export that
'expired有两个参数,第一个tpl是指模板文件名,第二id是指唯一标识符
if that.expired("cache","") then
'发送当前时间
that.assign "cache_time" , now()
'cache方法是指将它前面用assign方法分配的变量缓存起来
that.cache
'that.assign "var", now()
end if
that.assign "now_time" , now()
end sub
End Class
%>
复制代码
作者:
admin
时间:
2019-4-1 16:38
缓存要点:
1、判断缓存是否过期,用that.expired
2、默认缓存时间3600秒,即1小时可以通过config.asp文件重定义时间,call C_( Array("TMPL_CACHE_LIFETIME" , 1 )) 这样就1秒了
3、修改控制器文件缓存失效
4、缓存数据使用that.cache方法
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2