1 8 package examples.caching; 9 10 13 public class CacheTest { 14 public static void main(String [] 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 []{ 22 int.class 23 } 24 ); 25 int cacheInvocations = CacheStatistics.getNrOfCacheInvocationsFor( 26 "getPiDecimal", 27 new Class []{ 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 |