|  | 
 
| 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
%>
 | 
 |