Oracle
  Home arrow Oracle arrow Page 2 - 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 
 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: Hello Cache, How Are You Doing?
By: Mark Vilrokx
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2005-11-01

    Table of Contents:
  • Generic Architecture for Caching Table Data: Hello Cache, How Are You Doing?
  • The Cache Miss Ratio aka DB Reads
  • The Cache Turnover Ratio
  • Reporting the Ratio

  • 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: Hello Cache, How Are You Doing? - The Cache Miss Ratio aka DB Reads


    (Page 2 of 4 )

    When data is not found in the cache, it is called a cache miss.  A cache is only effective if it has a low miss rate.  The miss ratio can be calculated by dividing the number of times a record gets read from the DB (it only gets read from the DB if it wasn’t found in the cache, indicating a cache miss), versus the number of times a record was looked for:

                # Cache Misses

    Hit Ratio = -------------- * 100

                # Total Reads

    The lower the miss ratio, the fewer the data items get read from the database and the more performance gain you are experiencing from using the caching logic.  A high cache miss ratio can indicate that the cache size is too small, or that the data you are caching is not suitable for caching, i.e. there are too many distinct values that get queried resulting in high turnover (see later).

    In order to be able to calculate the ratio, we just need to keep track of the number of db reads (on top of the total number of reads which we already keep track of). 

       g_total_db_hits      PLS_INTEGER    := 0;

    And then we change our existing code to gather the numbers (if requested):

       FUNCTION read_from_db (p_dept_id IN dept.deptno%TYPE)
          RETURN department_tp
       AS
          l_dept_data   department_tp;
          CURSOR csr_dept_data (p_dept_id IN dept.deptno%TYPE)
          IS
             SELECT dname, loc
               FROM dept
              WHERE deptno = p_dept_id;
       BEGIN
          OPEN csr_dept_data (p_dept_id);
          FETCH csr_dept_data INTO l_dept_data;

          IF (csr_dept_data%FOUND)
          THEN
             IF (gather_stats)
             THEN
                g_total_db_hits :=   g_total_db_hits
                                   + 1;

             END IF;
          END IF;

          CLOSE csr_dept_data;
          RETURN l_dept_data;
       END read_from_db;

    Now we just need to create a procedure to actually perform the calculations of the ratio:

       FUNCTION db_hit_ratio
          RETURN NUMBER
       AS
          l_db_hit_ratio   NUMBER (10, 5);
       BEGIN
          IF (g_total_reads <> 0)
          THEN
             l_db_hit_ratio := (g_total_db_hits / g_total_reads) *
    100;
          END IF;

          RETURN l_db_hit_ratio;
       END db_hit_ratio;

    More Oracle Articles
    More By Mark Vilrokx


       · Last in the series, last chance to comment lads.Enjoy,Mark.
     

       

    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 1 hosted by Hostway