Idea of ASP Static Page

Source: Internet
Author: User
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.

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.