Today is relatively idle! The development of the last two websites gave me a lot of new ideas! I have read a lot of excellent code, but I have never found a pattern that fits my needs! Using the Cache Design for reference, I seem to have found a more convenient way of thinking. In fact, the static page here is not static in the true sense, but it can achieve the static page resolution efficiency, which has not been tested by the project for sharing.
<%
'Article Source: http://www.devjs.com
Const devjs_index = "index.html"
Const index_default_interval = 300
Dim slastupdate
'Use the application to save the last update time, and make a judgment on the page. The page is generated every 300 seconds (5 minutes ).
Slastupdate = Application ("index_last_update ")
If slastupdate = "" Or datediff ("S", slastupdate, now ()> index_default_interval then
'Call makeindex () to generate the page and change the last update time.
Makeindex ()
Slastupdate = now ()
Application ("index_last_update") = slastupdate
Response. Write "exceeds the default time, updated on" & slastupdate
Else
Response. Write "reads static pages, updated on" & 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
%>
If the page is updated after expiration, the static page is called directly without expiration. Two functions are also used and pasted together. Note that savetextfile () is written in overwrite mode.
This is 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 much easier than caching! In fact, many things can be done in makeindex (), such as reading template files and replacing them.