ASP中CACHE缓存技术
时间:2010-05-03 10:58:00
我认为在ASP中最好的办法是用编程实现定时刷新Cache,也就是说给Application中储存的设一个过期时间。当然,在ASP中Application对象没有这样一个ExpireTime属性。这需要用程序实现。
Code
ASP:default.asp
<%@Language=VBScript%>
<%Option Explicit%>
<%Response.Buffer=True%>
<!--#include file = "conn.asp"-->
<!--#include file = "GetCache.asp"-->
<HTML>
<HEAD>
<TITLE>ASP Cache演示</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</HEAD>
<BODY>
<h4>每隔10秒刷新Cache:</h4>
<%
response.Flush
GetHTMLStream
response.Write
HTMLStream
%>
</body>
</html>ASP:getcache.asp
<%
Const CACHE_DEFAULT_INTERVAL = 30 '每隔30秒刷新一次cache
Dim HTMLStream
Dim IsExpires
IsExpires = CacheExpires
Function CacheExpires
Dim strLastUpdate
Dim result strLastUpdate = Application("LastUpdate")
If (strLastUpdate = "") Or (CACHE_DEFAULT_INTERVAL < DateDiff("s", strLastUpdate, Now)) Then
result = true
SetLastUpdateTime
Else
result = false
End If
CacheExpires = result
End Function
Sub SetLastUpdateTime
Application.Lock
Application("LastUpdate") = CStr(now())
Application.UnLock
End Sub
Sub GetHTMLStream
If IsExpires Then
UpdateHTMLStream
End If
HTMLStream=Application("CACHE_HTMLStream")
End Sub
Sub UpdateHTMLStream
dim d
d = FetchHTMLStream
Application.Lock
Application("CACHE_HTMLStream") = d
Application.UnLock
End Sub
Function FetchHTMLStream
Dim rs ,strSQL, strHTML
Set rs = CreateObject("ADODB.Recordset")
strSQL = "select categoryID , categoryname from categories"
rs.Open strSQL, strConn,adOpenForwardOnly,adLockReadOnly
strHTML = strHTML & "<select name=""slt_search"">"
while (not rs.EOF)
strHTML = strHTML & "<option>"
strHTML = strHTML & rs.Fields("categoryname")
strHTML = strHTML & "</option>" rs.MoveNext
wend
strHTML = strHTML & "</select>"
rs.Close
Set rs = Nothing
FetchHTMLStream = strHTML
End Function
%>ASP:conn.asp
<!--METADATA NAME="Microsoft ActiveX Data Objects 2.5 Library" TYPE="TypeLib" UUID="{00000205-0000-0010-8000-00AA006D2EA4}"-->
<%
dim strConn
strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind"
%>
标签:cache,缓存,asp
0
投稿
猜你喜欢
Python3 利用face_recognition实现人脸识别的方法
2023-11-05 05:08:02
SQL Server小知识:Processor Affinity
2008-11-24 20:50:00
TypeScript中泛型的使用详细讲解
2024-04-17 10:35:23
浅谈Python之Django
2023-12-13 15:14:43
Mysql数据库性能优化三(分表、增量备份、还原)
2024-01-21 00:38:54
Asp函数介紹(37个常用函数)
2011-04-11 11:06:00
在Vue项目中使用Typescript的实现
2024-04-26 17:39:57
Python实现判断一个字符串是否包含子串的方法总结
2023-04-17 06:27:58
使用Python来编写HTTP服务器的超级指南
2022-12-28 20:40:24
Python全景系列之模块与包全面解读
2022-12-09 19:26:48
Mysql误删除DELETE数据找回操作指南
2024-01-16 20:48:18
PHP基于phpqrcode生成带LOGO图像的二维码实例
2023-11-23 23:47:18
CSS 几条经典的 CSS Tips
2008-08-20 18:40:00
JavaScript ES6 Class类实现原理详解
2024-02-24 07:54:49
python 多线程实现检测服务器在线情况
2021-12-11 15:15:58
解决给dom元素绑定click等事件无效问题的方法
2024-04-16 10:36:42
纯numpy卷积神经网络实现手写数字识别的实践
2023-11-08 10:44:50
mysql中json的使用方式详解
2024-01-27 14:39:43
mysql主从服务器同步心得体会第1/2页
2024-01-18 13:34:20
浅析C# web访问mysql数据库-整理归纳总结
2024-01-12 17:07:42