当前位置: 移动技术网 > IT编程>开发语言>Asp > asp 静态页面的另一种思路

asp 静态页面的另一种思路

2017年12月12日  | 移动技术网IT编程  | 我要评论
其实这里的静态页面并不是真正意义上的静态,但可以达到了静态页面的解析效率,还未经项目测试,拿来分享。
复制代码 代码如下:

<%
const devjs_index=""
const index_default_interval=300
dim slastupdate
'用application保存最后更新的时间,而在页面里做判断,每隔300秒(5分钟)就生成一次页面
slastupdate=application("index_last_update")
if slastupdate="" or datediff("s",slastupdate,now())>index_default_interval then
'调用makeindex()生成页面,同时更改最后更新时间
makeindex()
slastupdate=now()
application("index_last_update")=slastupdate
response.write "超出默认时间,更新于" & slastupdate
else
response.write "读取静态页面,更新于" & slastupdate
end if
response.write loadtextfile(server.mappath(devjs_index),"gb2312")

function makeindex()
scontent="<hr>" & now()
call savetextfile(server.mappath(devjs_index),"gb2312",scontent)
end function
%>

如果过期就更新页面,没有过期直接调用静态页面,这里还用到了两个函数,一并贴上,提醒注意一下,savetextfile()是以覆盖方式写入的
就是这一句 ostream.savetofile sfilepath,2
复制代码 代码如下:

<%
function loadtextfile(sfilepath,scharset)
dim ostream
set ostream=server.createobject("adodb.stream")
ostream.type=2
ostream.mode=3
ostream.open
ostream.charset=scharset
ostream.position=ostream.size
ostream.loadfromfile sfilepath
loadtextfile=ostream.readtext
ostream.close
set ostream=nothing
end function

function savetextfile(sfilepath,scharset,outstring)
savefile=false
dim ostream
set ostream = server.createobject("adodb.stream")
ostream.type=2
ostream.mode=3
ostream.open
ostream.charset=scharset
ostream.writetext = outstring
ostream.savetofile sfilepath,2
ostream.close
set ostream = nothing
savetextfile=true
end function
%>

这个比缓存省事,也直接的多!其实,在makeindex()里可以做很多事,比如读取模板文件进行替换这些。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网