KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > caching > CacheTest


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package examples.caching;
9
10 /**
11  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
12  */

13 public class CacheTest {
14     public static void main(String JavaDoc[] args) {
15         Pi pi = new Pi();
16         pi.getPiDecimal(3);
17         pi.getPiDecimal(4);
18         pi.getPiDecimal(3);
19         int methodInvocations = CacheStatistics.getNrOfMethodInvocationsFor(
20                 "getPiDecimal",
21                 new Class JavaDoc[]{
22                     int.class
23                 }
24         );
25         int cacheInvocations = CacheStatistics.getNrOfCacheInvocationsFor(
26                 "getPiDecimal",
27                 new Class JavaDoc[]{
28                     int.class
29                 }
30         );
31         if (cacheInvocations > 0) {
32             double hitRate = methodInvocations / cacheInvocations;
33             System.out.println("Hit rate: " + hitRate);
34         } else {
35             System.out.println("Hit rate: unavailable");
36         }
37     }
38 }
Popular Tags