|
Expire Cache :: 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-19463 | /dev :: home :: articles :: Caching Recorsets | 197 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 The other most important feature of a cache engine is the ability to expire (remove) cached entries from the storage. In our implementation, we will provide a method that will be manually called. We could also build an automatic expiration feature, but that would make things even more complex. So let's keep it simple: Public Sub Remove(SQL) 'Lock the application Application.Lock 'Check whether the data is in cache If dDataCache.Exists(SQL) Then 'It's in cache, so remove it dDataCache.Remove SQL End If 'Unlock the application Application.UnLock End Sub
The trick here is to know when to expire (remove) the cached entries.
The best approach would be calling the Remove() method when we are
sure that the underlying database table has changed. If that table
gets updated very often (such as in a few minutes) it might be useful
to delay calling Remove() for a couple of updates.
MyCache.ExpireTable "Customers" Then it would expire all entries such as: SELECT * FROM Customers SELECT FirstName FROM Customers WHERE CustomerID = 531 SELECT SUM(Balance) FROM Customers SELECT TOP 5 FROM Customers ORDER BY Balance DESC ... etc There we go: Public Sub ExpireTable(TableName) 'Get keys as an array aKeys = dDataCache.Keys 'How many entries? iCount = dDataCache.Count 'Enumerate cache For i = 0 To iCount - 1 'Get SQL sSQL = aKeys(i) sItemTable = "" 'Find the underlying table aSQL = Split(sSQL, " ") For iSQL = 0 To UBound(aSQL) - 1 'Look for FROM keyword If LCase(aSQL(iSQL)) = "from" Then 'Found it sItemTable = aSQL(iSQL + 1) Exit For End if Next If LCase(TableName) = LCase(sItemTable) Then 'Remove the entry dDataCache.Remove sSQL End If Next End Sub
A little bit tricky, but that's all we can do for now.
Public Sub RemoveAll Application.Lock dDataCache.RemoveAll Application.Unlock End Sub < Previous Part: GetRecordset Function > Next Part: Using the Cache Engine in your Projects |
Bot: Msn
echoPANEL, Free .NET
FogBugz Hosting Plans
|
| privacy policy , license , disclaimer , © 2000-2004, 2eNetWorX. [page generated in 63 ms.] |