Another idea for ASP static pages-Application tips

Source: Internet
Author: User
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.
Copy Code code as follows:

<%
Const devjs_index= "Index.html"
Const index_default_interval=300
Dim slastupdate
' Save the last updated time with application, and make a decision on the page to generate 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 "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= "Call Savetextfile (Server.MapPath (Devjs_index), "GB2312", scontent)
End Function
%>

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.
Copy 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 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.