Frog Frog Recommended: ASP in the simulation .NET Cache

xiaoxiao2021-03-06  37

In order to improve the performance of the website home page, the homepage will try to call data from the cache before you need to call the database display data.

If there is no available data in the cache to open the database to remove the record set, in order to make the page display data and the database synchronize within a certain period of time.

We set the expiration time of the cache to 30 seconds.

Disclaimer: Cache Management class is from the mobile network forum 7.0

Note: It is best not to directly cache objects of objects and objects of the status, such as direct cache records or database link objects.

->

<%

SUB Showrsarr (RSARR)

'2005-1-27 by Frog Frog Prince

'Displaying the table structure of the record set generated by the table

'

Response.write "

"

IF not ISempty (RSARR) THEN

For y = 0 to Ubound (RSARR, 2)

Response.write "

"

For x = 0 to Ubound (RSARR, 1)

Response.write "

"

Response.write "

" & RSARR (X, Y) & ""

NEXT

Response.write ""

NEXT

Else

Response.write "

no records "

Response.write ""

END IF

Response.write ""

End Sub

Class CLS_CACHE

REM ================== User description ============================= ============================================================================================================================================================================================================= ==

Rem = This class module is the original Network Pioneer, Author: Lost City prodigal son. If you use this class module, please do not remove this description. This comment does not affect the speed of the execution. =

REM = Role: Cache and Cache Management Class =

REM = public variable: RELOADTIME expiration time (in minutes) The default value is 14400, =

REM = MaxCount Cache the maximum value of the object, exceeds the object that automatically deletes less use. The default is 300 =

The total name of the REM = Cachename cache group, the default is "DVBBS", if there is more than one cache group in a site, you need to change this value externally. =

REM = Property: Name Defines Cache Object Name, write only property. =

REM = Property: Value Read and write cache data. =

REM = function: objiisempty () determines whether the current cache has expired. =

REM = Method: Delcahe (MyCahename) Manually deletes a cache object, the parameter is the name of the cache object. =

REM =============================================================================================================================================================================== ============================================================================================================================================================================================================= =========

Public ReloadTime, Maxcount, Cachename

Private Localcachename, Cachedata, Delcount

Private sub coplass_initialize ()

RELOADTIME = 14400

Cachename = "DVBBS"

End Sub

Private sub setche (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 <> "" "" thenchedata = 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, "Dvbbscachaserver", "please change the cachename."

END IF

End Property

Public property Get Value ()

If Localcachename <> "" "" ""

Cachedata = Application (Cachename & "_" & localcachename)

If isarray (cachedata) THEN

Value = cachedata (0)

Else

Err.raise VbobjectError 1, "DVBBSCACHSERVER", "The Cachedata IS Empty."

END IF

Else

Err.raise VbobjectError 1, "Dvbbscachaserver", "please change the cachename."

END IF

End Property

Public function objisempty ()

ObjiSempty = TRUE

Cachedata = Application (Cachename & "_" & localcachename)

IF not isarray (cachedata) THEN EXIT FUNCTION

IF not isdate (Cachedata (1)) THEN EXIT FUNCTION

If Datediff ("S", CDATE (Cachedata (1)), NOW ()) <60 * reloadtime THEN

ObjiSempty = false

END IF

END FUNCTION

Public Sub Delcahe (Mycahename)

Makeempty (Cachename & "_" & mycahename)

End Sub

END CLASS

DIM STRCONN, RS

StrConn = "driver = {SQL Server}; server = localhost; database = northwind; uid = sa; pwd = sa;"

Public function geteMPloyees ()

DIM SQL, RS, Cache

Set cache = new CLS_CACHE

Cache.reloadtime = 0.5

Cache.cachename = "WAWA"

Cache.name = "Employees"

If cache.objiisempty () THEN

SET RS = Server.createObject ("AdoDb.Recordset")

SQL = "SELECT EMPLOYEEID, LastName, Firstname from Employees Order by Employeeid DESC"

RS.Open SQL, STRCONN, 1, 1

Cache.value = rs.getrows (5)

Rs.close: set = Nothing

END IF

GetEmployees = Cache.Value

Set cache = Nothing

END FUNCTION

Showrsarr (getEmployees)

%>