An asp technique for improving homepage Performance

Source: Internet
Author: User

Brief Introduction: Generally, the homepage of a website has the largest access volume. If the homepage of your website is opened slowly, your customers will leave your website one after another. we usually cache data that requires complex operations or database queries or generate static webpages to Improve the Performance of web applications. This time, We cache the output of the home page into a string, then it is updated regularly, which takes care of the performance without affecting the timeliness of the homepage. some VBS custom classes, Application objects, XmlHttp objects, and adodb are used here. stream object. For more information, see.
It is best to keep this page and the page you want to cache in a directory, or some images with relative paths will not be displayed, and some cached pages will be garbled, I still don't know how to solve this problem. I may need to set the encoding type during Response. You can try it.

Copy codeThe Code is 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) *) & "milliseconds. "

Sub CacheXmlInfoIndex ()
Dim BodyText, xml
Set xml = Server. CreateObject ("Microsoft. XMLHTTP ")
'Replace the following address with the file address of your homepage. You must use an absolute path starting with http: //. You cannot write relative paths.
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 on this page
Class Cls_Cache
Rem ============================= instructions ======================================
Rem = this category of modules is original to the mobile network pioneer, Author: Lost City prodigal son. If this class module is used, do not remove this description. This annotation does not affect the execution speed. =
Rem = role: cache and Cache Management =
Rem = Public variable: Reloadtime expiration time (in minutes) Default Value: 14400, =
Rem = the maximum value of the MaxCount cached object. If the value exceeds the maximum value, objects that are used less frequently are automatically deleted. The default value is 300 =
Rem = the total name of the CacheName cache group. The default value is "Dvbbs". If a site contains more than one cache group, you need to change this value externally. =
Rem = attribute: Name defines the Name of the cache object and only writes the attribute. =
Rem = attribute: value reads and writes cached data. =
Rem = function: ObjIsEmpty () determines whether the current cache has expired. =
Rem = method: DelCahe (MyCaheName) manually deletes a cache object. The parameter is the name of the cache 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
%>

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.