Solution to the popular online cache class error '123'

Source: Internet
Author: User

Today, I checked the errors that were originally caused by bugs in the class and lack of rigorous programmer thinking. This error does not appear on all servers. This error is related to the server's IIS parsing capability, however, no matter whether an error is prompted or not, the bug exists, but it is only a matter of time before and after the error occurs. The following are the non-incorrect version cache classes I modified:

<%
Role: cache and Cache Management
'Public variable: OutTimes expiration time (in minutes); default value: 14400
'Cachename: The total name of the cache group. The default value is "Seven". If a site contains more than one cache group, this value needs to be changed externally.
'Property: Name defines the Name of the cache object and only writes the property.
'Attribute: value reads and writes cached data.
'Function: ObjIsEmpty () to determine whether the current cache has expired.
'Method: DelCahe (MyCaheName) manually deletes a cache object. The parameter is the name of the cache object.
Class DoCache
Public OutTimes, CacheName
Private LocalCacheName, CacheData, DelCount
Private Sub Class_Initialize ()
OutTimes = 14400
CacheName = "Seven"
End Sub
Private Sub SetCache (SetName, NewValue)
Application. Lock
Application (SetName) = NewValue
Application. unLock
End Sub
Private Sub makeEmpty (SetName)
Application. Lock
Application (SetName) = Empty
Application. unLock
End Sub
Public Property Let Name (ByVal vNewValue)
LocalCacheName = LCase (vNewValue)
End Property
Public Property Let Value (ByVal vNewValue)
If LocalCacheName <> "" Then
CacheData = Application (CacheName & "_" & LocalCacheName)
If IsArray (CacheData) Then
CacheData (0) = vNewValue
CacheData (1) = Now ()
Else
ReDim CacheData (2)
CacheData (0) = vNewValue
CacheData (1) = Now ()
End If
SetCache CacheName & "_" & LocalCacheName, CacheData
Else
Err. Raise vbObjectError + 1, "www.7di.net", "please change the CacheName ."
End If
End Property
Public Property Get Value ()
If LocalCacheName <> "" Then
CacheData = Application (CacheName & "_" & LocalCacheName)
If IsArray (CacheData) Then
Value = CacheData (0)
Else
Err. Raise vbObjectError + 1, "www.7di.net", "The CacheData Is Empty ."
End If
Else
Err. Raise vbObjectError + 1, "www.7di.net", "please change the CacheName ."
End If
End Property
Public Function ObjIsEmpty ()
ObjIsEmpty = True
CacheData = Application (CacheName & "_" & LocalCacheName)
If Not IsArray (CacheData) Then
ObjIsEmpty = False
Exit Function
End If
If Not IsDate (CacheData (1) Then
ObjIsEmpty = False
Exit Function
End If
If DateDiff ("s", CDate (CacheData (1), Now ()> 60 * OutTimes Then ObjIsEmpty = False
End Function
Public Sub DelCahe (MyCaheName)
MakeEmpty (CacheName & "_" & MyCaheName)
End Sub
End Class

'Call Method

Set MyCache = New DoCache
MyCache. OutTimes = 0.5 'defines the expiration time (in minutes)
MyCache. Name = "testcaches" 'defines the cache Name
IF MyCache. ObjIsEmpty () then' determines whether it is available (including expiration, and whether it is null)
Response. write "the output content is cached data:" & MyCache. Value
Else
BoardJumpList = "xxx"
MyCache. Value = BoardJumpList 'write content
Response. write "the output content is Uncached data:" & BoardJumpList
End if

'Mycache. DelCahe ("testcaches") 'is used to clear the cache.
%>

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.