<%
'文章来源:http://www.devjs.com
Const DEVJS_INDEX="index.html"
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()里可以做很多事,比如读取模板文件进行替换这些。