Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access Cache with .VBS

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
US
I'm building an HTA that accesses a database on SQL server using a .vbs file. The HTA will be run client side and it's housed on a shared drive.

I don't have any problem connecting/querying/building recordsets, and displaying them in the HTML, however the problem I am running into is with trying to cache the recordset... Is this even possible in a purely client side application like this. I understand that .net can access the cache object, but I can't get this to work the way I have things setup, it doesn't appear to recognize "cache."

My intention of using the cache is to minimize queries by storing some basic info during each use on the users pc. I've read that it's best to write the recordset to an array and cache the array. But I can't figure out how to access cache from a purely .vbs function. An example of the recordset data would be a 15 row, 4 column array of data.

I figure I could always write the array to a text file on the user's PC, but I was hoping for a slicker solution.

Can anyone point me toward a solution, or an example of doing this? Thanks in advance for taking the time to read this!
 
HAve you tried the GetRows method of the ADODB.Recordset object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the reply! I found an article online that had a good example of how to do this, however, it is using the cache object that's in the global.asa file. I'm not running this on a server though, it's being accessed from a share drive in a public folder. I'm also assuming that the cache object that this version is accessing is server side. I am curious if there is a way to access the user's cache on their machine to store this array using .vbs. Here is the example that I found online below... when I try to run this I get errors on any line that includes cache because a cache object is not recognized (I'm assuming do to a lack of a global.asa file)...?

Code:
Option Explicit

Sub Application_OnStart
    Cache.FlushEnabled = True 
    Cache.FlushTimeout = 600000 
    Cache.FlushInterval = 30000 
End Sub
 

Function GetRecordset()
    Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "SELECT title_id, title, price FROM titles", connStr
    Set GetRecordset = rs
End Function

Function GetCachedArray()
    GetCachedArray = Cache("cachedArray")

    If IsEmpty(GetCachedArray) Then
        Dim rs
        Set rs = GetRecordset()
        GetCachedArray = rs.GetRows()
        Dim bAdded
        bAdded = Cache.Add("cachedArray", GetCachedArray, 60000)

        If bAdded Then
            Response.Write "<div style=""color:red"">Cache Refreshed</div>"
        End If
    End If

End Function


Dim cachedArray
cachedArray = GetCachedArray()

Dim nLastRow, iRow
nLastRow = UBound(cachedArray, 2)

For iRow = 0 To nLastRow
    Response.Write "<tr><td>" & cachedArray(0, iRow) & "</td>"
    Response.Write "<td>" & cachedArray(1, iRow) & "</td>"
    Response.Write "<td>$" & cachedArray(2, iRow) & "</td></tr>" & vbCRLF
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top