欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP实例:利用缓存提高数据显示效率】,下面是详细的分享!
ASP实例:利用缓存提高数据显示效率
<%
Function DisplayRecords()
Dim sql, conn, rs
sql="SELECT id, [szd_f], [szd_t] FROM admin"
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&Server.MapPath("db.mdb")
Set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 1, 3
If Not rs.EOF Then
Dim temp
temp="<table width=""90%"" align=""center"""
temp=temp & " border=""1"" bordercolor=""silver"""
temp=temp & " cellspacing=""2"" cellpadding=""0"">"
temp=temp & "<tr bgcolor=""#CCDDEE""><td width=""5%"""
temp=temp & ">ID</td><td>操作</td>"
temp=temp & "<td>数值</td></tr>"
While Not rs.EOF
temp=temp & "<tr><td bgcolor=""#CCDDEE"">"
temp=temp & rs("ID") & "</td><td>" & rs("szd_f")
temp=temp & "</td><td>" & rs("szd_t")
temp=temp & "</td></tr>"
rs.MoveNext
Wend
temp=temp & "</table>"
DisplayRecords=temp
Else
DisplayRecords="Data Not Available."
End If
rs.Close
conn.Close
Set rs=Nothing
Set conn=Nothing
End Function
'写入缓存
Function DisplayCachedRecords(Secs)
Dim retVal, datVal, temp1
retVal=Application("cache_demo")
datVal=Application("cache_demo_date")
If datVal="" Then
datVal=DateAdd("s",Secs,Now)
End If
temp1=DateDiff("s", Now, datVal)
If temp1 > 0 And retVal <> "" Then
DisplayCachedRecords=retVal
' Debugging Code :
Response.Write "<b><font color=""green"">利用缓存读取数据"
Response.Write " ... (" & temp1 & " 秒剩余)</font></b>"
Response.Write "<br><br>"
Else
Dim temp2
' Change DisplayRecords() to the function whose
' value you want to cache
temp2=DisplayRecords()
Application.Lock
Application("cache_demo")=temp2
Application("cache_demo_date")=DateAdd("s",Secs,Now)
Application.UnLock
DisplayCachedRecords=temp2
' Debugging Code :
Response.Write "<b><font color=""red"">刷新缓存显示 ..."
Response.Write "</font></b><br><br>"
End If
End Function
%>
<!--
Response.Write DisplayRecords()
-->
<html>
<head>
<title>利用缓存从数据库---读取数据</title>
<style>
body, p, td { font-family:Sans-Serif; font-size:8pt; }
td { padding-left: 5; }
</style>
</head>
<body>
<%
Dim t1, t2
t1=Timer
Response.Write DisplayCachedRecords(20)
t2=Timer
%>
<p align="center">
停留时间: <%=Left((CDbl((t2 - t1) * 1000.0)), 5) %> ms
</p>
</body>
</html>
以上所分享的是关于ASP实例:利用缓存提高数据显示效率,下面是编辑为你推荐的有价值的用户互动:
相关问题:c#如何使用缓存提高程序效率
答:缓存的技术应用应该是非广泛的。而它的作用也是为了提高系统或者网站的执行效率。下面是四种常见的缓存技术: 一.OutputCaching 由于IIS的一些特性,默认情况下OutputCache是打开的,但是要对某些请求进行缓存,还需要开发者进行定制,而且默认... >>详细
相关问题:怎样利用缓存提高ASP.NET网站速度
答:大多数时候,默认的优先级已经足够了-缓存引擎可以正常完成任务并处理缓存的内存管理。CacheItemRemovedCallback选项考虑到一些很有趣的可能性,但实际上它很少使用。不过,为了说明该方法,我将提供它的一个使用示例:CacheItemRemovedCallback... >>详细
相关问题:javaweb项目s2sh框架怎么提高hibernate的运行效率 ...
答:你好 Hibernate的缓存分为: 一级缓存:在Session级别的,在Session关闭的时候,一级缓存就失效了。 二级缓存:在SessionFactory级别的,它可以使用不同的缓存实现,如EhCache、JBossCache、OsCache等。 缓存的注释写法如下,加在Entity的java类... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
