先鋒緩衝類(極度加速ASP和提高執行效率)

來源:互聯網
上載者:User
clsCache 公用屬性 
引用內容:
 valid   返回是否有效。true表示有效,false表示無效。唯讀。 
 Version  擷取類的版本資訊。唯讀。 
 value   返回緩衝內容。唯讀。 
 name  設定緩衝名稱,寫入。 
 expire  設定緩衝到期時間,寫入。 

 
 
clsCache 公用方法 

引用內容:
 add(Cache,ExpireTime)  對緩衝賦值(緩衝內容,到期時間) 
 clean()  清空緩衝 
 verify(cache2)  比較緩衝值是否相同——返回是或否。 

 
  
clsCache 使用樣本 

程式碼:
<!--#include file="clsCache" -->
<%
dim content,myCache
set myCache=new cache
myCache.name="lkstar" '定義緩衝名稱 
if myCache.valid then '如果緩衝有效
content=myCache.value '讀取緩衝內容
else
content="......" '大量內容,可以是非常耗時大量資料庫查詢記錄集
myCache.add content,dateadd("n",1000,now) '將內容賦值給緩衝,並設定緩衝有效期間是目前時間+1000分鐘
end if 
set clsCache=nothing '釋放對象
%>
程式碼:
<% 
'-------------------------------------------------------------------------------------
'轉寄時請保留此聲明資訊,這段聲明不並會影響你的速度!
'**************************   【先鋒緩衝類】Ver2004  ********************************
'作者:孫立宇、apollosun、ezhonghua
'官方網站:http://www.lkstar.com   支援人員論壇:http://bbs.lkstar.com
'電子郵件:kickball@netease.com    線上QQ:94294089
'著作權聲明:著作權沒有,盜版不究,源碼公開,各種用途均可免費使用,歡迎你到技術論壇來尋求支援。
'目前的ASP網站有越來越龐大的趨勢,資源和速度成了瓶頸
'——利用伺服器端緩衝技術可以很好解決這方面的矛盾,大大加速ASP運行和改善效率。
'本人潛心研究了各種演算法,應該說,這個類是當前最快最純淨的緩衝類。
'詳細使用說明或範例請見下載附件或到本人官方網站下載!
'--------------------------------------------------------------------------------------
class clsCache
'----------------------------
private cache           '緩衝內容
private cacheName       '緩衝Application名稱
private expireTime      '緩衝到期時間
private expireTimeName  '緩衝到期時間Application名稱
private path            '快取頁面URL路徑

private sub class_initialize()
path=request.servervariables("url")
path=left(path,instrRev(path,"/"))
end sub
 
private sub class_terminate()
end sub

Public Property Get Version
 Version="先鋒緩衝類 Version 2004"
End Property

public property get valid '讀取緩衝是否有效/屬性
if isempty(cache) or (not isdate(expireTime)) then
vaild=false
else
valid=true
end if
end property

public property get value '讀取當前緩衝內容/屬性
if isempty(cache) or (not isDate(expireTime)) then
value=null
elseif CDate(expireTime)<now then
value=null
else
value=cache
end if
end property

public property let name(str) '設定緩衝名稱/屬性
cacheName=str&path
cache=application(cacheName)
expireTimeName=str&"expire"&path
expireTime=application(expireTimeName)
end property

public property let expire(tm) '設定緩衝到期時間/屬性
expireTime=tm
application.Lock()
application(expireTimeName)=expireTime
application.UnLock()
end property

public sub add(varCache,varExpireTime) '對緩衝賦值/方法
if isempty(varCache) or not isDate(varExpireTime) then
exit sub
end if
cache=varCache
expireTime=varExpireTime
application.lock
application(cacheName)=cache
application(expireTimeName)=expireTime
application.unlock
end sub

public sub clean() '釋放緩衝/方法
application.lock
application(cacheName)=empty
application(expireTimeName)=empty
application.unlock
cache=empty
expireTime=empty
end sub
 
public function verify(varcache2) '比較緩衝值是否相同/方法——返回是或否
if typename(cache)<>typename(varcache2) then
 verify=false
elseif typename(cache)="Object" then
 if cache is varcache2 then
  verify=true
 else
  verify=false
 end if
elseif typename(cache)="Variant()" then
 if join(cache,"^")=join(varcache2,"^") then
  verify=true
 else
  verify=false
 end if
else
 if cache=varcache2 then
  verify=true
 else
  verify=false
 end if
end if
end function
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.