Today is quite free! 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.
<%
'Article source: http://www.devjs.com
Const DEVJS_INDEX=index.htmlConst INDEX_DEFAULT_INTERVAL=300Dim sLastUpdate' uses Application to save the last updated time, and makes 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 and is updated in & sLastUpdateElse Response.Write reads the static page, updated at & sLastUpdateEnd IfResponse.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
<%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=NothingEnd 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=trueEnd 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.