An idea of implementing static page in ASP

Source: Internet
Author: User

It's a little more free today! The recent development of two websites has brought me a lot of new ideas! Also read a lot of good code, but always did not find a pattern in line with their own! Using the cache design, I seem to have found a more convenient way of thinking. 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.

<%

' Article Source: http://www.devjs.com

Const devjs_index= "index.html"
const index_default_interval=300
Dim slastupdate
' Save the last updated time with application, and in the page make a judgment, every 300 seconds (5 minutes) to generate a page
slastupdate=application ("index_last_update")
if Slastupdate= "" or DateDiff ("s", Slastupdate,now ()) >index_default_interval Then
' invokes MakeIndex () to generate the page,  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= "

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.

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