1 5 6 7 11 12 package org.joseki.util.cache; 13 14 16 public class CacheTest 17 { 18 19 public static void main(String [] args) 20 { 21 if (System.getProperty("java.util.logging.config.file") == null) 22 System.setProperty("java.util.logging.config.file", "etc/logging.properties"); 23 24 Cache c = new Cache(4, new ItemFactoryTest(), new CachePolicyLRU() ) ; 25 26 for ( int i = 0 ; i < 5 ; i++) 27 { 28 Integer val = new Integer (i) ; 29 String key = val.toString() ; 30 c.put(key, val) ; 31 } 32 33 34 get(c, new Integer (1).toString()) ; 35 get(c, new Integer (2).toString()) ; 36 get(c, new Integer (3).toString()) ; 37 get(c, new Integer (9).toString()) ; 38 } 39 40 static void get(Cache c, Object k) 41 { 42 Object obj = c.get(k) ; 43 System.out.println(k + " => "+obj) ; 44 } 45 46 47 static class ItemFactoryTest implements CacheItemFactory 48 { 49 50 public Object create(Object key) 51 { 52 return key ; 53 } 54 55 public void destroy(Object key, Object obj) 56 { 57 } 58 59 } 60 } 61 62 63 | Popular Tags |