国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

在JScript中使用緩存技術的實際代碼

2024-05-04 11:00:46
字體:
來源:轉載
供稿:網友
在使用VBScript時,我們可以用Application緩存數組來實現緩存,例:

程序代碼:
復制代碼 代碼如下:
Dim rs,arr 
rs.Open conn,sql,1,1 
arr=rs.GetRows() 
Application.Lock() 
Application("cache")=arr 
Applicatoin.UnLock() 

在VBScript里,數組是可以存到Application對象里的,但是如果ASP的語言選擇為JScript的話,那么就有些不妙了,我們在使用Application儲存一個數組時,會出現以下錯誤:

引用內容:
Application object, ASP 0197 (0x80004005)

Disallowed object use

Cannot add object with apartment model behavior to the application intrinsic object.

在微軟的知識庫可以找到具體原因如下:

引用內容:
JScript arrays are considered to be "Apartment" COM components. Only Component Object Model (COM) components that aggregate the Free Threaded Marshaler (FTM) can be assigned to Application scope within an Internet Information Server (IIS) 5.0 ASP page. Because an "Apartment" component cannot aggregate the FTM (it cannot allow a direct pointer to be passed to its clients, unlike a "Both with FTM" object), JScript arrays do not aggregate the FTM. Therefore, JScript arrays cannot be assigned to Application scope from an ASP page.

以上描述引用自:PRB: Error When You Store a JScript Array in Application Scope in IIS 5.0

因此,為了解決這個問題,在Google里找了一大會,終于找到了一篇文章《Application對象的Contents和StaticObjects做Cache的一些結論》,解決了這個問題,方法就是使用Application.StaticObject存放一個Scripting.Dictionary對象,然后再使用Scripting.Dictionary對象來存放需要緩存的數據。

據此,寫了一個操作緩存的類,實現put、get、remove和clear方法,使用之前,需要在global.asa中添加一個object:

程序代碼:
<object id="xbsCache" runat="server" scope="Application" progid="Scripting.Dictionary"></object>
類的實現如下:
復制代碼 代碼如下:
<script language="JScript" runat="server"> 
/** 
 Title: cache operate class 
 Description: operate system cache 
 @Copyright: Copyright (c) 2007 
 @Author: xujiwei 
 @Website: http://www.xujiwei.cn/ 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳州市| 公安县| 蓝山县| 漳浦县| 灵山县| 马边| 剑阁县| 疏勒县| 香河县| 贡山| 鄂尔多斯市| 留坝县| 铜鼓县| 崇州市| 新丰县| 昌邑市| 南康市| 固镇县| 黎川县| 阿瓦提县| 合阳县| 罗定市| 辽宁省| 新田县| 墨竹工卡县| 肃宁县| 荔波县| 靖州| 遂溪县| 永丰县| 高安市| 安岳县| 施秉县| 邹城市| 安乡县| 银川市| 伊吾县| 汉中市| 高台县| 田东县| 济阳县|