The development of the two recent websites has given me a lot of new ideas! I have also read a lot of excellent codes, but I have never found a pattern that suits me! Drawing on the cache design, I seem to have found a more convenient way of thinking. In fact, the static pages here are not static in the true sense, but they can achieve the parsing efficiency of static pages. They have not been tested by the project and are shared here.
Copy the code code as follows:
<%
Const DEVJS_INDEX=index.html
Const INDEX_DEFAULT_INTERVAL=300
Dim sLastUpdate
'Use Application to save the last updated time, and make judgments on the page, generating a page 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 in & sLastUpdate
Else
Response.Write reads the static page, updated with & 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 it is expired, update the page. If it is not expired, call the static page directly. Two functions are also used here. Paste them together. Please note that SaveTextFile() is written in an overwriting method.
This is the sentence oStream.SaveToFile sFilePath,2
Copy the code code as follows:
<%
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 less troublesome than caching and much more straightforward! In fact, you can do a lot of things in MakeIndex(), such as reading template files and replacing them.