Programs | caching | Performance <!--Frog Frog Recommendation: Using caching to improve the performance of ASP programs-->
<!--in order to improve the performance of ASP programs, people often use the data cached in application,
But when you modify the database how to let application update, this article provides you with a reasonable solution,
If anyone has a better algorithm, please post a discussion, thank you
-->
<%
Class wawa_app_getrows
Public Function wawa_get_list (strapp,strconn,strsql)
'********************************
' Function: Extract the array from the application, and then call the Wawa_get_rows () function to assign a value to the application if the data in application is a empty value.
' You can empty the corresponding application value into empty when you modify the database, which automatically updates the application when you browse.
' If you update the database (for example, add, modify, or delete the data) then remove the corresponding application variable after modifying the database,
' Use one of the following statements to empty the specified application value, where the Strapp parameter is the application variable name to remove
' Application. Contents.Remove (Strapp)
'********************************
Dim Wawa
Wawa = Application (Strapp)
If IsEmpty (Wawa) Then
Wawa = Wawa_get_rows (strconn,strsql)
Application (Strapp) = Wawa
End If
Wawa_get_list = Wawa
End Function
Public Function wawa_get_rows (strconn,strsql)
'********************************
' function: Read the record from the database and use the GetRows method
' Save the record as an array
'
'********************************
Dim Rs_wawa
Set Rs_wawa = CreateObject ("ADODB. Recordset ")
Rs_wawa. Open strsql,strconn,,1,1
Wawa_get_rows = Rs_wawa. GetRows ()
Rs_wawa. Close
Set Rs_wawa = Nothing
End Function
End Class
%>
<!--Here is an example to illustrate how the above class uses-->
<%
Dim strapp,strsql,strconn
strapp= "Xinwendongtai"
Strsql= "SELECT Top 5 id,title from Wen where lei=161 order by id DESC"
strconn= "Driver={sql Server};server=192.168.0.110;database=new;uid=sa;pwd=sa;"
Set Wawa_temp=new wawa_app_getrows
Arr_xinwendongtai=wawa_temp.wawa_get_list (Strapp,strconn,strsql)
%>
<table width= "100%" border= "0" cellspacing= "1" >
<% If UBound (arr_xinwendongtai) <>0 Then%>
<% for I=0 to UBound (arr_xinwendongtai,2)-1%>
<tr>
<td><a href= "view.asp?id=<%= Arr_xinwendongtai (0,i)%>" ><%= Arr_xinwendongtai (1,i)%></a ></td>
</tr>
<% Next%>
<% Else%>
<tr>
<td> There's no news yet </td>
</tr>
<% End If%>
</table>