Frog Frog recommended: ASP in the simulation. NET Cache

Source: Internet
Author: User
Tags object exit empty sql
Cache <!--
In order to improve the performance of the home page, the home page usually needs to call the database to display data in the first attempt to invoke data from the cache,
If there is no data available in the cache and then open the database to fetch the recordset, in order for the page to display the data and the database synchronized within a certain time,
We set the cache expiration time to 30 seconds.
Disclaimer: Cache Management class from the Dynamic Network Forum 7.0
Note: It is best not to cache objects with state objects and MTA schemas directly in the cache, such as caching recordsets directly or database linked objects.
-->
<%
Sub Showrsarr (Rsarr)
' 2005-1-27 by Frog Frog Prince
' Table structure to display the array of GetRows generated by a recordset
'
Response.Write "<table width=100% border=0 cellspacing=0 cellpadding=0>"
If not IsEmpty (Rsarr) Then
For y=0 to Ubound (rsarr,2)
Response.Write "<tr>"
For x=0 to Ubound (rsarr,1)
Response.Write "<td>" &rsarr (x,y) & "</td>"
Next
Response.Write "</tr>"

Next
Else
Response.Write "<tr>"
Response.Write "<td colspan=" &rs.fields.count-1& ">no records</td>"
Response.Write "</tr>"
End If
Response.Write "</table>"
End Sub
Class Cls_cache
Rem ================== Use Instructions =================================================================================
Rem = This class module is the pioneer of the dynamic network, the author: The Prodigal son of the city. If you use this class module, please do not remove this description. This comment does not affect the speed of execution. =
Rem = function: Cache and cache Management class =
Rem = public variable: reloadtime expiration (in minutes) The default value is 14400, =
Rem = Maxcount The maximum value of the cached object, exceeding automatically deleting objects that are less frequently used. The default value is 300 =
Rem = The total name of the CacheName cache group, the default value is "Dvbbs", and if there is more than one cache group in a site, you need to change this value externally. =
Rem = attribute: Name defines cache object names, write-only properties. =
Rem = attribute: Value reads and writes cached data. =
Rem = function: Objisempty () Determines whether the current cache expires. =
Rem = method: Delcahe (Mycahename) Deletes a cached object manually, and the parameter is the name of the cached object. =
Rem ===========================================================================================================
Public Reloadtime,maxcount,cachename
Private Localcachename,cachedata,delcount
Private Sub Class_Initialize ()
reloadtime=14400
Cachename= "Dvbbs"
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, "Dvbbscacheserver", "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, "Dvbbscacheserver", "the CacheData is Empty."
End If
Else
Err.Raise vbObjectError + 1, "Dvbbscacheserver", "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.objisempty () Then
Set Rs=server.createobject ("ADODB



Related Article

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.