亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

asp緩存類代碼

時(shí)間:2020-11-12 14:21:27 ASP 我要投稿

asp緩存類代碼

  至于緩存的作用,我想我也不用再多說了,它的作用已經(jīng)很明顯,特別是對于信息量非常大或是全數(shù)據(jù)庫頁面的網(wǎng)站,他能很好地利用主機(jī)的內(nèi)存資源,加速ASP的執(zhí)行效率,減輕服務(wù)器的負(fù)擔(dān),而動(dòng)網(wǎng)在這一方面做得是最突出的,像他現(xiàn)在的dvbbs7.1.0版,更是在緩存的利用上更上一層樓,前后臺(tái)大多的操作都和緩存有關(guān),而現(xiàn)在動(dòng)網(wǎng)里用的也就是迷城浪子的緩存類,下面列出動(dòng)網(wǎng)的.三大高手寫的ASP緩存類

  木鳥寫的

  復(fù)制代碼 代碼如下:

 。***

  'vbsCache類

 。

 。傩詖alid,是否可用,取值前判斷

  '屬性name,cache名,新建對象后賦值

  '方法add(值,到期時(shí)間),設(shè)置cache內(nèi)容

 。傩詖alue,返回cache內(nèi)容

 。傩詁lempty,是否未設(shè)置值

  '方法makeEmpty,釋放內(nèi)存,測試用

 。Х椒╡qual(變量1),判斷cache值是否和變量1相同

 。Х椒╡xpires(time),修改過期時(shí)間為time

  '木鳥2002.12.24

 。ttp://www.aspsky.net/

 。***

  classCache

  privateobj'cache內(nèi)容

  privateexpireTime'過期時(shí)間

  privateexpireTimeName'過期時(shí)間application名

  privatecacheName'cache內(nèi)容application名

  privatepath'uri

  privatesubclass_initialize()

  path=request.servervariables("url")

  path=left(path,instrRev(path,"/"))

  endsub

  privatesubclass_terminate()

  endsub

  publicpropertygetblEmpty

 。欠駷榭

  ifisempty(obj)then

  blEmpty=true

  else

  blEmpty=false

  endif

  endproperty

  publicpropertygetvalid

 。欠窨捎(過期)

  ifisempty(obj)ornotisDate(expireTime)then

  valid=false

  elseifCDate(expireTime)<nowthen

  valid=false

  else

  valid=true

  endif

  endproperty

  publicpropertyletname(str)

 。гO(shè)置cache名

  cacheName=str&path

  obj=application(cacheName)

  expireTimeName=str&"expires"&path

  expireTime=application(expireTimeName)

  endproperty

  publicpropertyletexpires(tm)

 。е卦O(shè)置過期時(shí)間

  expireTime=tm

  application.lock

  application(expireTimeName)=expireTime

  application.unlock

  endproperty

  publicsubadd(var,expire)

  '賦值

  ifisempty(var)ornotisDate(expire)then

  exitsub

  endif

  obj=var

  expireTime=expire

  application.lock

  application(cacheName)=obj

  application(expireTimeName)=expireTime

  application.unlock

  endsub

  publicpropertygetvalue

 。≈

  ifisempty(obj)ornotisDate(expireTime)then

  value=null

  elseifCDate(expireTime)<nowthen

  value=null

  else

  value=obj

  endif

  endproperty

  publicsubmakeEmpty()

  '釋放application

  application.lock

  application(cacheName)=empty

  application(expireTimeName)=empty

  application.unlock

  obj=empty

  expireTime=empty

  endsub

  publicfunctionequal(var2)

 。П容^

  iftypename(obj)<>typename(var2)then

  equal=false

  elseiftypename(obj)="Object"then

  ifobjisvar2then

  equal=true

  else

  equal=false

  endif

  elseiftypename(obj)="Variant()"then

  ifjoin(obj,"^")=join(var2,"^")then

  equal=true

  else

  equal=false

  endif

  else

  ifobj=var2then

  equal=true

  else

  equal=false

  endif

  endif

  endfunction

  endclass

  木鳥類例子vbsCache類

 。

 。傩詖alid,是否可用,取值前判斷

  '屬性name,cache名,新建對象后賦值

 。Х椒╝dd(值,到期時(shí)間),設(shè)置cache內(nèi)容

 。傩詖alue,返回cache內(nèi)容

 。傩詁lempty,是否未設(shè)置值

 。Х椒╩akeEmpty,釋放內(nèi)存,

 。Х椒―elCahe,刪除內(nèi)存

 。Х椒╡qual(變量1),判斷cache值是否和變量1相同

 。Х椒╡xpires(time),修改過期時(shí)間為time

 。в梅

  setmyCache=NewCache

  myCache.name="BoardJumpList"'定義緩存名

  ifmyCache.validthen'判斷是否可用(包括過期,與是否為空值)

  response.writemyCache.value'輸出

  else

  ................

  BoardJumpList=xxx

  myCache.addBoardJumpList,dateadd("n",60,now)'寫入緩存xxx.add內(nèi)容,過期時(shí)間

  response.writeBoardJumpList'輸出

  endif

  myCache.makeEmpty()釋放內(nèi)存

  mycache.DelCahe()刪除緩存

  迷城浪子寫的

  復(fù)制代碼 代碼如下:

  ClassCls_Cache

  Rem==================使用說明====================

  Rem=本類模塊是動(dòng)網(wǎng)先鋒原創(chuàng),作者:迷城浪子。如采用本類模塊,請不要去掉這個(gè)說明。這段注釋不會(huì)影響執(zhí)行的速度。

  Rem=作用:緩存和緩存管理類

  Rem=公有變量:Reloadtime過期時(shí)間(單位為分鐘)缺省值為14400

  Rem=MaxCount緩存對象的最大值,超過則自動(dòng)刪除使用次數(shù)少的對象。缺省值為300

  Rem=CacheName緩存組的總名稱,缺省值為"Dvbbs",如果一個(gè)站點(diǎn)中有超過一個(gè)緩存組,則需要外部改變這個(gè)值。

  Rem=屬性:Name定義緩存對象名稱,只寫屬性。

  Rem=屬性:value讀取和寫入緩存數(shù)據(jù)。

  Rem=函數(shù):ObjIsEmpty()判斷當(dāng)前緩存是否過期。

  Rem=方法:DelCahe(MyCaheName)手工刪除一個(gè)緩存對象,參數(shù)是緩存對象的名稱。

  Rem========================

  PublicReloadtime,MaxCount,CacheName

  PrivateLocalCacheName,CacheData,DelCount

  PrivateSubClass_Initialize()

  Reloadtime=14400

  CacheName="Dvbbs"

  EndSub

  PrivateSubSetCache(SetName,NewValue)

  Application.Lock

  Application(SetName)=NewValue

  Application.unLock

  EndSub

  PrivateSubmakeEmpty(SetName)

  Application.Lock

  Application(SetName)=Empty

  Application.unLock

  EndSub

  PublicPropertyLetName(ByValvNewValue)

  LocalCacheName=LCase(vNewValue)

  EndProperty

  PublicPropertyLetValue(ByValvNewValue)

  IfLocalCacheName<>""Then

  CacheData=Application(CacheName&"_"&LocalCacheName)

  IfIsArray(CacheData)Then

  CacheData(0)=vNewValue

  CacheData(1)=Now()

  Else

  ReDimCacheData(2)

  CacheData(0)=vNewValue

  CacheData(1)=Now()

  EndIf

  SetCacheCacheName&"_"&LocalCacheName,CacheData

  Else

  Err.RaisevbObjectError+1,"DvbbsCacheServer","pleasechangetheCacheName."

  EndIf

  EndProperty

  PublicPropertyGetValue()

  IfLocalCacheName<>""Then

  CacheData=Application(CacheName&"_"&LocalCacheName)

  IfIsArray(CacheData)Then

  Value=CacheData(0)

  Else

  Err.RaisevbObjectError+1,"DvbbsCacheServer","TheCacheDataIsEmpty."

  EndIf

  Else

  Err.RaisevbObjectError+1,"DvbbsCacheServer","pleasechangetheCacheName."

  EndIf

  EndProperty

  PublicFunctionObjIsEmpty()

  ObjIsEmpty=True

  CacheData=Application(CacheName&"_"&LocalCacheName)

  IfNotIsArray(CacheData)ThenExitFunction

  IfNotIsDate(CacheData(1))ThenExitFunction

  IfDateDiff("s",CDate(CacheData(1)),Now())<60*ReloadtimeThen

  ObjIsEmpty=False

  EndIf

  EndFunction

  PublicSubDelCahe(MyCaheName)

  makeEmpty(CacheName&"_"&MyCaheName)

  EndSub

  EndClass

  迷城浪子類例子

  SetWydCache=NewCls_Cache

  WydCache.Reloadtime=0.5'定義過期時(shí)間(以分鐘為單會(huì))

  WydCache.CacheName="pages"'定義緩存名

  IFWydCache.ObjIsEmpty()Then''判斷是否可用(包括過期,與是否為空值)

  Response.writeWydCache.Value

  Else

  ..................

  BoardJumpList=xxx

  WydCache.Value=BoardJumpList'寫入內(nèi)容

  Response.writeBoardJumpList

  Endif

  mycache.DelCahe("緩存名")刪除緩存

  slightboy寫的'========================

  復(fù)制代碼 代碼如下:

 。lsCache.asp

 。========================

  '==begin:2004-6-2621:51:47

 。==copyright:slightboy(C)1998-2004

 。==email:slightboy@msn.com

 。========================

  '========================

 。imApplication(2)

 。pplication(0)Counter計(jì)數(shù)器

 。pplication(1)dateTime放置時(shí)間

 。pplication(2)Content緩存內(nèi)容

  PublicPREFIX

  PublicPREFIX_LENGTH

  PrivateSubClass_Initialize()

  PREFIX="Cached:"

  PREFIX_LENGTH=7

  EndSub

  PrivateSubClass_Terminate

  EndSub

  '設(shè)置變量

  PublicPropertyLetCache(ByRefKey,ByRefContent)

  DimItem(2)

  Item(0)=0

  Item(1)=Now()

  IF(IsObject(Content))Then

  SetItem(2)=Content

  Else

  Item(2)=Content

  EndIF

  Application.Unlock

  Application(PREFIX&Key)=Item

  Application.Lock

  EndProperty

 。〕鲎兞坑(jì)數(shù)器++

  PublicPropertyGetCache(ByRefKey)

  DimItem

  Item=Application(PREFIX&Key)

  IF(IsArray(Item))Then

  IF(IsObject(Item))Then

  SetCache=Item(2)

  Else

  Cache=Item(2)

  EndIF

  Application(PREFIX&Key)(0)=Application(PREFIX&Key)(0)+1

  Else

  Cache=Empty

  EndIF

  EndProperty

  '檢查緩存對象是否存在

  PublicPropertyGetExists(ByRefKey)

  DimItem

  Item=Application(PREFIX&Key)

  IF(IsArray(Item))Then

  Exists=True

  Else

  Exists=False

  EndIF

  EndProperty

 。У玫接(jì)數(shù)器數(shù)值

  PublicPropertyGetCounter(ByRefKey)

  DimItem

  Item=Application(PREFIX&Key)

  IF(IsArray(Item))Then

  Counter=Item(0)

  EndIF

  EndProperty

 。гO(shè)置計(jì)數(shù)器時(shí)間

  PublicPropertyLetdateTime(ByRefKey,ByRefSetdateTime)

  DimItem

  Item=Application(PREFIX&Key)

  IF(IsArray(Item))Then

  Item(1)=SetdateTime

  EndIF

  EndProperty

  '得到計(jì)數(shù)器時(shí)間

  PublicPropertyGetdateTime(ByRefKey)

  DimItem

  Item=Application(PREFIX&Key)

  IF(IsArray(Item))Then

  dateTime=Item(1)

  EndIF

  EndProperty

 。е刂糜(jì)數(shù)器

  PublicSubResetCounter()

  DimKey

  DimItem

  Application.Unlock

  ForEachKeyinApplication.Contents

  IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then

  Item=Application(Key)

  Item(0)=0

  Application(Key)=Item

  EndIF

  Next

  Application.Lock

  EndSub

 。h除某以緩存

  PublicSubClear(ByRefKey)

  Application.Contents.Remove(PREFIX&Key)

  EndSub

 。蹇諞]有使用的緩存

  PublicSubClearUnused()

  DimKey,Keys,KeyLength,KeyIndex

  ForEachKeyinApplication.Contents

  IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then

  IF(Application(Key)(0)=0)Then

  Keys=Keys&VBNewLine&Key

  EndIF

  EndIF

  Next

  Keys=Split(Keys,VBNewLine)

  KeyLength=UBound(Keys)

  Application.Unlock

  ForKeyIndex=1ToKeyLength

  Application.Contents.Remove(Keys(KeyIndex))

  Next

  Application.Lock

  EndSub

  '清空所有緩存

  PublicSubClearAll()

  DimKey,Keys,KeyLength,KeyIndex

  ForEachKeyinApplication.Contents

  IF(Left(Key,PREFIX_LENGTH)=PREFIX)Then

  Keys=Keys&VBNewLine&Key

  EndIF

  Next

  Keys=Split(Keys,VBNewLine)

  KeyLength=UBound(Keys)

  Application.Unlock

  ForKeyIndex=1ToKeyLength

  Application.Contents.Remove(Keys(KeyIndex))

  Next

  Application.Lock

  EndSub

  EndClass

  slightboyn類例子SetWyd=NewJayCache

  Wyd.dateTime("Page")=時(shí)間

  IfWyd.Exists("Page")Then

  Response.writeWyd.Cache("Page")'輸出

  Else

  Wyd.Cache("Page")=xxx寫入

  Responxe.writexxx

  EndIF

  Wyd.Clear("page")'刪除緩存

【asp緩存類代碼】相關(guān)文章:

1.關(guān)于ASP模板類代碼參考

2.asp.net 操作INI文件讀寫類實(shí)例代碼

3.asp分頁代碼是什么

4.asp購物車代碼

5.asp獲取當(dāng)前URL代碼實(shí)例

6.ASP加法驗(yàn)證碼代碼

7.asp.net 組合模式的PHP代碼

8.關(guān)于AJAX類代碼