9.3.5 data Cache
The first thing to note is that both the data cache and the recordset cache are used to improve performance, but they are irrelevant. The data cache is a temporary data store that allows data in the cache to be used instead of regenerating new data. This applies only to data that is not frequently changed but is accessed multiple times.
One of the easiest ways to cache data in an ASP is to use application and session-scoped variables. For example, suppose there are some pages that need to select a book type. Normally, you might create a include file that contains the following functions.
<%
Function Booktypes ()
Dim Rsbooktypes
Dim Strquote
Strquote = Chr (34)
Set rsbooktypes = Server.CreateObject ("ADODB. Recordset ")
' Get the book types
Rsbooktypes.open "Usp_booktypes", strconn
Response.Write "<select name=" & Strquote & Lstbooktype & strquote & ">"
While not rsbooktypes.eof
Response.Write & "<OPTION>" & Rsbooktypes ("Type") & "</OPTION>"
Rsbooktypes.movenext
Wend
Response.Write & "</SELECT>"
Rsbooktypes.close
Set rsbooktypes = Nothing
End Function
%>
This is just a call to a stored procedure to get the type of book and create a select list. The disadvantage of the preceding code is that the database must be accessed each time the function is invoked. So, modify this function again.
<%
Function Booktypes ()
Dim Rsbooktypes
Dim Strquote
Dim strlist
' The ' if ' the list is in the cache
Strlist = Application ("Booktypes")
If strlist = "" Then
' Not cached, so builds up list and cache it
Strquote = Chr (34)
Set rsbooktypes = Server.CreateObject ("ADODB. Recordset ")
' Get the book types
Rsbooktypes.open "Usp_booktypes", strconn
Strlist = "<select name=" & Strquote & Lstbooktype & strquote & ">"
While not rsbooktypes.eof
Strlist = strlist & "<OPTION>" & Rsbooktypes ("type") & "</OPTION>"
Rsbooktypes.movenext
Wend
Strlist = strlist & "</SELECT>"
Rsbooktypes.close
Set rsbooktypes = Nothing
' Check the list
Application ("booktypes") = Strlist
End If
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