01: /**************************************************************************************
02: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package examples.caching;
08:
09: /**
10: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
11: */
12: public class CacheTest {
13: public static void main(String[] args) {
14: Pi pi = new Pi();
15: pi.getPiDecimal(3);
16: pi.getPiDecimal(4);
17: pi.getPiDecimal(3);
18: int methodInvocations = CacheStatistics
19: .getNrOfMethodInvocationsFor("getPiDecimal",
20: new Class[] { int.class });
21: int cacheInvocations = CacheStatistics
22: .getNrOfCacheInvocationsFor("getPiDecimal",
23: new Class[] { int.class });
24: if (cacheInvocations > 0) {
25: double hitRate = methodInvocations / cacheInvocations;
26: System.out.println("Hit rate: " + hitRate);
27: } else {
28: System.out.println("Hit rate: unavailable");
29: }
30: }
31: }
|