欢迎光临
我们一直在努力

巧用缓存提高ASP应用程序的性能-ASP教程,ASP应用

建站超值云服务器,限时71元/月

为了提高asp程序的性能,人们常常将经常使用的数据缓存在 application,但是你修改了数据库后怎么让application更新呢,本文给你提供了一个合理的解决办法。

<%
class wawa_app_getrows
public function wawa_get_list(strapp,strconn,strsql)
 ********************************
 功能:从application中提取数组,如果application中的数据为empty值的时候再调用wawa_get_rows()函数来给application赋值.
  ,你可以在修改数据库的时候把相应的application值清空成empty,这就浏览的时候就会自动更新application了
  如果你更新了数据库(比如说添加,修改或者删除了数据)那么在修改数据库后把相应的application变量去掉,
  用下面的一条语句来实现清空指定的application值,其中strapp参数是要去掉的application变量名
  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)
 ********************************
 功能:从数据库里读取记录并用getrows方法
  把记录保存成一个数组
 
 ********************************
 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
%>
<!– 下面举个例子来说明上面的那个类怎么使用 –>
<%
 dim strapp,strsql,strconn
 strapp=”employee”
 strsql=”select employeeid,titleofcourtesy,firstname,lastname,title,city from employees”
 strconn=”driver={sql server};server=192.168.0.110;database=northwind;uid=sa;pwd=sa;”
 set wawa_temp=new wawa_app_getrows
 arr_wawa=wawa_temp.wawa_get_list(strapp,strconn,strsql)
%>

<%
 response.write(“<table width=100% border=0 cellspacing=1>”)
 dim i,j,rows,flds
 rows=ubound(arr_wawa,2)
 flds=ubound(arr_wawa,1)
 if rows>=0 then
  for i=0 to rows
   response.write(“<tr>”)
   for j=0 to flds
    response.write”<td>”&arr_wawa(j,i)&”</td>”
   next
   response.write(“</tr>”)
  next
 else
  response.write(“<tr><td>”&rows&”</td></tr>”)
 end if
 response.write(“</table>”)
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 巧用缓存提高ASP应用程序的性能-ASP教程,ASP应用
分享到: 更多 (0)