Oracle
  Home arrow Oracle arrow Page 3 - Generic Architecture for Caching Table...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ORACLE

Generic Architecture for Caching Table Data: Supercharge Your Cache
By: Mark Vilrokx
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2005-10-18

    Table of Contents:
  • Generic Architecture for Caching Table Data: Supercharge Your Cache
  • Switching the cache on and off
  • Don’t Forget to Flush
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Generic Architecture for Caching Table Data: Supercharge Your Cache - Don’t Forget to Flush


    (Page 3 of 4 )

    If you run this code you will notice some very peculiar behavior.  Although the cache gets switched off before the second call, it will refuse to query the database.  In fact, if you run it a second time (and a third etc.), you will see the same behavior, it just will not go to the DB.  That is until you reconnect (i.e. close this session and open a new one).  The reason is that switching the cache off doesn’t actually clear it.  The data that was in the cache before you switched it off stays in there until you disconnect your session.  Therefore, when you query department 10, it will still find it in the cache and return the cached value.

    Now you could have avoided this by adding the check to verify whether the cache is in use or not before you read from the cache.  But that would hide the fact that there is still data in the cache, occupying valuable memory for no reason.  To resolve this issue we will create a procedure that empties the cache and we will call this when the cache gets switched off.

       PROCEDURE flush_cache
       AS
       BEGIN
          g_dept_cache.DELETE;
       END flush_cache;

    Here are the changes needed in set_caching:

       PROCEDURE set_caching (p_on IN BOOLEAN DEFAULTTRUE)
       AS
       BEGIN
          g_caching := p_on;
          IF (NOT p_on)
          THEN
             flush_cache;
          END IF;
       END set_caching;

    Now, when you switch the cache off, you also clean it up and no further cache reads will occur, until you switch the cache back on that is. 

    And how do I know this switch actually works?  Well, very simple, I can now do my performance test that I did in the first article with the same procedure, dept_data, and just switch the cache on and off before each test (in part 1 of this series I could only demonstrate this by calling the read_from_db function directly).  It should be significantly slower with the cache switched off.

    More Oracle Articles
    More By Mark Vilrokx


       · Hi,Second in the series, please provide any feedback as you...
       · Hi!On Page #3 you wrote that "... there is still data in the cache, occupying...
       · Hi,Thank you for your comments. I must say, I did use to free up the memory...
       · Nice Article about caching. I have some additions to this article.If the application...
     

       

    ORACLE ARTICLES

    - Tuning PL/SQL Code
    - Debugging PL/SQL Code
    - Testing PL/SQL Code
    - Working With PL/SQL Code
    - Conditional Compilation for Oracle Database ...
    - Compile-Time Warnings for Oracle DB 10g
    - Compiling PL/SQL Code for an Oracle Database
    - Troubleshooting PL/SQL Code
    - Managing PL/SQL Code
    - Data Manipulation and More for HTML DB Appli...
    - Oracle Database Fundamentals
    - Adding Processes to HTML DB Applications
    - Adding Computations, Processes, and Validati...
    - Sub-templates and More with Oracle HTML DB
    - Focusing on Templates in Oracle HTML DB





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway