ASP improve the performance of the home page a skill _asp class

Source: Internet
Author: User
Brief introduction: General A Web site's first visit is the largest, if your site's home page open very slowly, your customers will be leaving your site. Often we cache data that requires complex operations or query databases, or generate static Web pages to improve the performance of Web applications. This time we directly cache the output of the first page into a string, and then updated regularly, that is, take care of the performance, but does not affect the timeliness of the home page. Here are some VBS custom classes, application objects, XMLHTTP objects, ADODB.stream objects, Relevant knowledge you can look up the information to understand.
It is best to let this page and you want to cache the page in a directory, or some relative path of the picture can not be displayed, and the other cached pages will appear garbled, I do not know how to solve this problem, may be in the response need to set the type of coding, we can try

Copy Code code as follows:

<%
Dim Wawa,startime,endtime
Startime=timer ()
Set wawa=new Cls_cache
Wawa. reloadtime=0.5
Wawa. Cachename= "Wawa"
Wawa. Name= "Xmlinfoindex"
If Wawa. Objisempty () Then Cachexmlinfoindex ()
Response.Write Wawa.value
Endtime=timer ()
Response.Write "<br> Execution Time:" & FormatNumber ((endtime-startime) *1000,5) & "milliseconds. "

Sub Cachexmlinfoindex ()
Dim BodyText, XML
Set XML = Server.CreateObject ("Microsoft.XMLHTTP")
' Replace the following address with the address of your home page, be sure to use the absolute path beginning with http://, cannot write relative path
Xml. Open "Get", "http://onlytiancai/bak/vote/InfoIndex.asp", False
Xml. Send
Bodytext=xml. Responsebody
Bodytext=bytestobstr (BodyText, "gb2312")
Wawa. Value=bodytext
Set xml = Nothing
End Sub
Function Bytestobstr (Body,cset)
Dim objstream
Set objstream = Server.CreateObject ("ADODB.stream")
Objstream. Type = 1
Objstream. Mode =3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. Type = 2
Objstream. Charset = Cset
Bytestobstr = objstream. ReadText
Objstream. Close
Set objstream = Nothing
End Function
%>
<%
' The following class can be saved in a separate file and then included in this page
Class Cls_cache
Rem ================== Use Instructions ==============================================
Rem = This class module is the pioneer of the dynamic network, the author: The Prodigal son of the city. If you use this class module, please do not remove this description. This comment does not affect the speed of execution. =
Rem = function: Cache and cache Management class =
Rem = public variable: reloadtime expiration (in minutes) The default value is 14400, =
Rem = Maxcount The maximum value of the cached object, exceeding automatically deleting objects that are less frequently used. The default value is 300 =
Rem = The total name of the CacheName cache group, the default value is "Dvbbs", and if there is more than one cache group in a site, you need to change this value externally. =
Rem = attribute: Name defines cache object names, write-only properties. =
Rem = attribute: Value reads and writes cached data. =
Rem = function: Objisempty () Determines whether the current cache expires. =
Rem = method: Delcahe (Mycahename) Deletes a cached object manually, and the parameter is the name of the cached object. =
Rem ================================================================
Public Reloadtime,maxcount,cachename
Private Localcachename,cachedata,delcount
Private Sub Class_Initialize ()
reloadtime=14400
Cachename= "Dvbbs"
End Sub
Private Sub Setcache (setname,newvalue)
Application.Lock
Application (setname) = NewValue
Application.UnLock
End Sub
Private Sub Makeempty (setname)
Application.Lock
Application (setname) = Empty
Application.UnLock
End Sub
Public Property Let Name (ByVal vnewvalue)
Localcachename=lcase (Vnewvalue)
End Property
Public Property Let Value (ByVal vnewvalue)
If localcachename<> "" Then
Cachedata=application (cachename& "_" &localcachename)
If IsArray (cachedata) Then
CacheData (0) =vnewvalue
CacheData (1) =now ()
Else
ReDim CacheData (2)
CacheData (0) =vnewvalue
CacheData (1) =now ()
End If
Setcache cachename& "_" &localcachename,cachedata
Else
Err.Raise vbObjectError + 1, "Dvbbscacheserver", "Please change the cachename."
End If
End Property
Public Property Get Value ()
If localcachename<> "" Then
Cachedata=application (cachename& "_" &localcachename)
If IsArray (cachedata) Then
Value=cachedata (0)
Else
Err.Raise vbObjectError + 1, "Dvbbscacheserver", "the CacheData is Empty."
End If
Else
Err.Raise vbObjectError + 1, "Dvbbscacheserver", "Please change the cachename."
End If
End Property
Public Function Objisempty ()
Objisempty=true
Cachedata=application (cachename& "_" &localcachename)
If not IsArray (cachedata) Then Exit Function
If not IsDate (CacheData (1)) Then Exit Function
If DateDiff ("s", CDate (CacheData (1)), now ()) < 60*reloadtime Then
Objisempty=false
End If
End Function
Public Sub Delcahe (mycahename)
Makeempty (cachename& "_" &mycahename)
End Sub
End Class
%>
Related Article

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.