Caching classes and opening database connection functions

Source: Internet
Author: User
Tags exit
function | cache | data | database | Database connection Lazy person's work, my company commander a little bit of code, have written function ...

Use up, can be lazy, haha ...


<% ' @ LANGUAGE = VBScript CodePage = 936

Dim JZ
Set jz=new Jz_clsmain
Jz. Cache_count=0
Jz.web_name= "Chinese SME Resource Network"

Class Jz_clsmain

Public rs,conn,sql,db
Public Web_name,t,t_s,t_h,cache
Public i_0,i_1
Public Reloadtime,cachename,localcachename,cache_data,cache_count

Private Sub Class_Initialize ()
ReDim db (4), Conn (4), RS (4), SQL (4)
ReDim T (20,4), t_s (20,3)
Reloadtime=14400*60
' Cachenamecachename=replace (replace (Server.MapPath ("/"), "/", ""), ":", ""), "\", "" "
Cachename=request.servervariables ("url")
Cachename=left (Cachename,instrrev (CacheName, "/")) & "JZ"
cache_count=1000
Web_name= "The Carpenter clan"
End Sub


Private Sub Class_Terminate ()
I_1=lbound (DB)
For I_0=0 to I_1
On Error Resume Next
' Response.Write (i_0& "<br/><br/>")
If IsObject (RS (i_0)) then RS (i_0). Close:set rs (i_0) =nothing
If IsObject (Conn (i_0)) Then Conn (I_0). Close:set Conn (i_0) = Nothing
Next
End Sub

Public Function tree_00 (STR_0)
Dim i,jz_temp (1)
For I=0 to Str_0
Jz_temp (0) =jz_temp (0) &jz_temp (1)
Jz_temp (1) = ".. /"
Next
Tree_00=jz_temp (0)
End Function

Public Function conn_00 (str_0,str_1)
Str_1=tree_00 (str_1)
DB (Str_0) = "Provider = Microsoft.jet.oledb.4.0;data Source =" & Server.MapPath (str_1& "Data/data_" &str_0 & ". mdb")
' Response.Write (db (STR_0))
End Function

' str0=0-4< defines the selected db (STR0) and defines Conn (STR0) and RS (STR0) >;str1=true,false< whether to create a database connection >;str2=true,false< Whether to create RS objects >;
Public Function c_r_s (STR0,STR1,STR2)
On Error Resume Next
If Str1 Then
Set Conn (STR0) = Server.CreateObject ("ADODB. Connection ")
Conn (STR0). Open db (STR0)
End If
If STR2 Then
Set Rs (STR0) = Server.CreateObject ("ADODB"). Recordset ")
End If
End Function

Public Function c_r_o (STR0,STR1,STR2)
Rs (STR0). Open SQL (STR0), Conn (STR0), str1, str2
If ERR Then
Err. Clear
Set Conn (STR0) = Nothing
Response.Write "Database connection error, please check the connection string. "' Note, you need to translate these words into English.
Response.End
End If
End Function


Public Function c_r_e (STR0,STR1,STR2)
On Error Resume Next
If STR2 Then
RS (STR0). Close
Set RS (STR0) =nothing
End If
If Str1 Then
Conn (STR0). Close
Set Conn (STR0) =nothing
End If
End Function

Public Property Let Name (ByVal vnewvalue)
Localcachename = LCase (vnewvalue)
End Property
Public Property Let Value (ByVal vnewvalue)
If localcachename<> "" Then
ReDim Cache_data (2)
Cache_data (0) =vnewvalue
Cache_data (1) =now ()
Cache_data (2) =reloadtime
Application.Lock
Application (CacheName & "_" & localcachename) = Cache_data
Application.UnLock
Else
Err.Raise vbObjectError + 1, "Jzcacheserver", "Please change the cachename."
End If
End Property
Public Property Get Value ()
If localcachename<> "" Then
Cache_data=application (CacheName & "_" & Localcachename)
If IsArray (cache_data) Then
Value=cache_data (0)
Else
Err.Raise vbObjectError + 1, "Jzcacheserver", "The Cache_data (" &LocalCacheName& ") is Empty."
End If
Else
Err.Raise vbObjectError + 1, "Jzcacheserver", "Please change the cachename."
End If
End Property

Public Function Objisempty ()
App_count ()
Objisempty=true
Cache_data=application (CacheName & "_" & Localcachename)
If not IsArray (cache_data) Then Exit Function
If not IsDate (Cache_data (1)) Then Exit Function
If IsEmpty (Cache_data (2)) Then Exit Function
If DateDiff ("s", CDate (Cache_data (1)), now ()) < (Cache_data (2)) Then Objisempty=false

End Function

Public Sub Delcahe (mycahename)
Application.Lock
Application.Contents.Remove (cachename& "_" &mycahename)
Application.UnLock
End Sub

Public Sub App_count ()
If Application.contents.count>cache_count Then
Application.Lock
Appli



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.