2eNetWorX :: Development Community with Tutorial, Script, Code, Programming sections for Visual Basic, Active Server Pages and .Net Framework Developers.  

Cache Storage for Recordset :: Article - 2eNetWorX


This article explains how to build a Recordset caching system for your ASP web site to greatly improve the performance.

 
  2eNetWorX :: ASP, VB, Asp.Net, Vb.Net, C#, dotNet, .Net OpenSource Projects
MyDev What's New | Projects | Tutorials & Articles | Services | Stats | Contact Us
Guest-01422    /dev :: home :: articles :: Caching Recorsets  252 online visitors
Popular Projects

  • TableEditor
  • StatCounteX
  • 2eNetWorX/Dev
  • MiniSurvey
  • OpenForum
  • PowerTool
  • ShopEZ
  • Trans-It
  • HiLiteR
  • (View All Projects)


    Top 10

    » Contributions


    Tutorials & Articles

    » Recordset Cache
    » OpenSource
    » Statisticus
    » OpenCYA!


    Code Samples

    » Undocumented...
    » Ask For Login
    » DSN'less Connection
    » Who's Online?
    » (All Samples)


    Link Back



    Site Banner


  • Improving Database Performance by Caching serialized Recordsets

    by Hakan Eskici

    Part 1 - Key Features and Design
    Part 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

    Cache Storage

    Having proposed the interface of our Cache class, we now make use of the global.asa file for our internal storage.

    We will use an application level Scripting.Dictionary object which is very stable and thread-safe. It enables us to store key-value pairs, and to retrieve stored values by specifying keys. In our implementation, we will use the SQL statements as the unique key.

    However, this would impose a risk of messing things up when the same SQL strings are present for different databases. For example, if there are two databases with Customers tables in each, our cache engine might not know which Customers table you are referring to. It is possible to overcome this issue by prefixing the SQL statement with the connection ID (or maybe the connection string itself) to generate really unique keys.

    If your website already has a global.asa file, place the following line on the top of it:

    <Object Runat="Server" Scope="application" ID="dDataCache" 
    ProgID="Scripting.Dictionary"></Object>
    
    Here, we tell the Asp engine that we would like to have a global dictionary object with name "dDataCache". We can access this object from any of our Asp pages later on.

    If there is no global.asa file on your site, you can simply create an empty text file and rename it to global.asa and that's it. Please note that the file must be located on the application root. (Not to mention your web site must be defined as an application).

    Implementation

    We have a storage, and a class interface. Now it is time to implement the features.

    Let's start with the constructor and destructor of our class. A constructor is a special method of a class that is automatically executed when the class is instantiated by declaring it as an object. A destructor is the method that is run when the object is disposed (destroyed by setting to Nothing).

    Class DataCache
    
    'Connection string to connect to the database
    Public ConnectionString
    
    'Stream object for our internal use
    Private stCache
    
    'Constructor
    Private Sub Class_Initialize()
    	Set stCache = Server.CreateObject("AdoDB.Stream")
    	stCache.Type = 1 'adTypeBinary
    end sub
    
    'Destructor
    Private Sub Class_Terminate()
    	Set stCache = Nothing
    End Sub
    	
    End Class
    

    We use the AdoDB.Stream object for serialization & deserialization of the Recordsets. Therefore we create one in the constructor.

    As being the core of our cache engine, now we will build the mighty GetRecordset() function.

    < Previous Part: Key Features and Design
    > Next Part: GetRecordset Function





    Who's Online

     Bot: Msn
     Bot: Google
     (190) guests
     (60) repeated

    How is this done?


    Popular Web Sites

      echoPANEL, Free .NET
      Webserver Control Panel

      FogBugz Hosting Plans
      SubVersion Hosting Plans
      SourceGear Vault
      Hosting Plans

    Admin's Toolbox

    Web Database Management
    Web Site Statistics
    Survey Manager
    Integrated forum for webpages
    OpenSource WebSite Framework


      privacy policy , license , disclaimer , © 2000-2004, 2eNetWorX.   [page generated in 78 ms.]