|
Cache Engine :: Article - 2eNetWorX
|
|||
| 2eNetWorX :: ASP, VB, Asp.Net, Vb.Net, C#, dotNet, .Net OpenSource Projects |
| MyDev | What's New | Projects | Tutorials & Articles | Services | Stats | Contact Us |
| Guest-18966 | /dev :: home :: articles :: Caching Recorsets | 125 online visitors |
» Contributions
» Recordset Cache » OpenSource » Statisticus » OpenCYA!
» Undocumented... » Ask For Login » DSN'less Connection » Who's Online? » (All Samples)
|
Improving Database Performance by Caching serialized Recordsetsby Hakan Eskici Part 1 - Key Features and DesignPart 2 - Cache Storage and Implementation Part 3 - GetRecordset Function Part 4 - Cache Expiration and Removal Part 5 - Using the Cache Engine in your Projects Part 6 - Case Study and Final Words
Well, we have a fully working cache engine implementation, but how do we use it?
There are two things in your task list: <% Dim conn, rs Dim SQL, sConn Set conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _ "Data Source=C:\Data\Customers.mdb" conn.Open sConn Set rs.ActiveConnection = conn rs.CursorType = 3 'adOpenStatic SQL = "SELECT SUM(Balance) AS Total FROM Customers" rs.Open SQL,,,2 'adCmdTable Response.Write "Total = " & rs("Total") rs.Close conn.Close Set rs = Nothing Set conn = Nothing %>
If there are thousands of records in the Customers table, performing
a SUM would take up to a few seconds each time you visit the page
with that code.
<!--#include file="cache.asp"--> <% 'Declare cache and recordset objects Dim MyCache, rs Dim SQL, sConn 'Create an instance of the DataCache Set MyCache = New DataCache 'Specify the connection string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _ "Data Source=C:\Data\Customers.mdb" MyCache.ConnectionString = sConn 'Get a recordset from the cache SQL = "SELECT SUM(Balance) AS Total FROM Customers" Set rs = MyCache.GetRecordset(SQL) Response.Write "Total = " & rs("Total") rs.Close Set rs = Nothing Set MyCache = Nothing %>
The GetRecordset() function will only take long time when it's first called.
(Of course, not any longer than the classic connection / recordset method).
Later calls will immediately return your recordset in a few miliseconds.
That's hundreds of times faster!
|
Bot: Google
echoPANEL, Free .NET
FogBugz Hosting Plans
|
| privacy policy , license , disclaimer , © 2000-2004, 2eNetWorX. [page generated in 31 ms.] |