Application of CACHECLS Caching _asp class

Source: Internet
Author: User
Copy Code code as follows:

<%
Rem =================================================================
Rem = class: Cachecls
Rem = Description: Caching applications
Rem = revision:1.01 Beta
Rem = Author: Shong Hero (cexo255)
Rem = Date:2005/05/6 18:38:10
Rem = qq:30133499
Rem = Mysite:http://www.relaxlife.net
Rem = Download: Http://www.Relaxlife.net/cexo/Cache_pro.rar
Rem = QQ Group: 4341998
Rem = applicable: For some commonly used, but infrequently changed data into the cache, call faster than every time to read from the database to be fast n accompany
Rem =================================================================

CacheName = "RL"
Class Cachecls
Private Localcachename, Cache_data

Public Property Let Name (ByVal vnewvalue)
Localcachename = LCase (vnewvalue)
Cache_data=application (CacheName & "_" & Localcachename)
End Property

Public Property Let Value (ByVal vnewvalue)
Dim N,i,newvaluearr
If localcachename<> "" Then
N = Countinstr (Vnewvalue, "|")
Newvaluearr = Split (Vnewvalue, "|", -1,1)
ReDim Cache_data (N)
For i = 0 to N
Cache_data (i) = Newvaluearr (i)
Next
Application.Lock
Application (CacheName & "_" & localcachename) = Cache_data
Application.UnLock
Else
Response.Write "Set cache error, or cache name cannot be empty, please update cache"
Response.End ()
End If
End Property

Public Property Get Value ()
If localcachename<> "" Then
If IsArray (cache_data) Then
Value=cache_data
End If
Else
Response.Write "Set cache error, or cache name cannot be empty, please update cache"
Response.End ()
End If
End Property

' Take the value in the specified cache
Public Function Getcachevalue (mycahename)
Getcachevalue = Application (CacheName & "_" & Mycahename)
End Function

' Take all cache names
Public Function Getallcachename ()
Dim Cacheobj
For each cacheobj in application.contents
Getallcachename = getallcachename & Cacheobj & ","
Next
Getallcachename = Left (Getallcachename,len (getallcachename)-1)
Getallcachename = Replace (Getallcachename,cachename & "_", "")
End Function

' Release cache
Public Sub Delcahe (mycahename)
Application.Lock
Application.Contents.Remove (CacheName & "_" & Mycahename)
Application.UnLock
End Sub

' Free all Caches
Public Sub Removeallcache ()
Dim Cachelist,i
Cachelist=split (Getallcachename (), ",")
If UBound (cachelist) >0 Then
For i=0 to UBound (cachelist)
Delcahe Cachelist (i)
Next
End If
End Sub

' Count the number of occurrences of char chars in str
Private Function countinstr (Str,char)
COUNTINSTR = 0
Dim I, Charlen
Charlen = Len (Char)
For i = 1 to Len (STR)
If Mid (Str, I, charlen) = Char Then countinstr = countinstr + 1
Next
End Function

End Class

Dim Cachepro
Set Cachepro = New cachecls
' Set cache ' cexo255 ' and its value: ' cexo2551|cexo2552|cexo2553|cexo2554|cexo2555 '
Cachepro.name = "cexo255"
Cachepro.value = "cexo2551|cexo2552|cexo2553|cexo2554|cexo2555"
' Take the value in the current cache
' Cachearr = Cachepro.value

Cachepro.name = "WXF"
Cachepro.value = "WXF"
Cachepro.name = "DW"
Cachepro.value = "DW"

' Release Cache cexo255
' Cachepro.delcahe ("cexo255")

' Free all Caches
' Cachepro.removeallcache

' Take the value in the cexo255 cache
Cachearr = Cachepro.getcachevalue ("cexo255")
If IsArray (Cachearr) Then
For i = 0 to UBound (Cachearr)
Response.Write Cachearr (i) & "<br>"
Next
Else
Response.Write "Cache is freed!!! "
End If

Set Cachepro = Nothing
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.