It's a little more free today! The recent development of two websites has brought me a lot of new ideas! Also read a lot of good code, but always did not find a pattern in line with their own! Using the cache design, I seem to have found a more convenient way of thinking. In fact, the static page here is not a true sense of static, but can reach the static page parsing efficiency, but also without project testing, to share.
<%
' Article Source: http://www.devjs.com
Const devjs_index= "index.html"
const index_default_interval=300
Dim slastupdate
' Save the last updated time with application, and in the page make a judgment, every 300 seconds (5 minutes) to generate a page
slastupdate=application ("index_last_update")
if Slastupdate= "" or DateDiff ("s", Slastupdate,now ()) >index_default_interval Then
' invokes MakeIndex () to generate the page, Change the last update time
makeindex ()
slastupdate=now ()
application ("Index_last_update") =slastupdate
Response.Write "exceeded the default time, updated on" & Slastupdate
Else
Response.Write "read static page, updated on" & Slastupdate
End If
Response.Write Loadtextfile (Server.MapPath (Devjs_index), "GB2312")
Function makeindex ()
Scontent= "
If the expiration of the update page, there is no expiration of the direct call static page, here also used two functions, together, note that the Savetextfile () is written in the overwrite way
That's the 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
%>
This is more convenient than caching, but also directly more! In fact, there are many things you can do in MakeIndex (), such as reading template files to replace them.