Tuesday, December 4, 2007

How to get your data faster with data cache

How to get your data faster with data cache

To get your data faster with data cache

If you want to speed up your data retrieval rate you can use data caching to improve the performance of your database.

Here’s how:

sub cachedata()

dim rsData, aData

' Put valid data into application("GLOBAL_SHIPPING_UPDATE")

if (not isdate(application("GLOBAL_SHIPPING_UPDATE"))) then

application.lock

application("GLOBAL_SHIPPING_UPDATE") = #12/31/1990#

application.unlock

end if

' If last update more than 5 minutes old then refresh

if (abs(datediff("n", application("GLOBAL_SHIPPING_UPDATE"), now())) >= 5) then

' Get data

set rsData = server.createobject("adodb.recordset")

rsData.open "select * from ShippingMethod", DBCONN

if (not rsData.eof) then aData = rsData.getrows()

rsData.close

set rsData = nothing

' Store in global memory

application.lock

application("GLOBAL_SHIPPING") = aData

application("GLOBAL_SHIPPING_UPDATE") = now()

application.unlock

end if

end sub

Displaying the results.

sub drawMethods()

dim aData, i, sMethod, sDescription

' Get the latest data

call cachedata()

aData = application("GLOBAL_SHIPPING")

if (not isarray(aData)) then

response.write "Error: No data available."

exit sub

end if

response.write ""

end sub


No comments: