private static void getMap(){
LRUMap cache = new LRUMap( 5 );
// Populate the cache with 5 stock prices
cache.put( " MSFT " , new Float( 0.03 ) );
cache.put( " TSC " , new Float( 0.001 ) );
cache.put( " LU " , new Float( 23.30 ) );
cache.put( " CSCO " , new Float( 242.20 ) );
cache.put( " P " , new Float( 10.23 ) );
// Now use some of the entries in the cache
Float tscPrice = (Float) cache.get( " TSC " );
Float cscoPrice = (Float) cache.get( " CSCO " );
Float msPrice = (Float) cache.get( " MSFT " );
Float luPrice = (Float) cache.get( " LU " );
Float pPrice = (Float) cache.get( " P " );
Float msPrice2 = (Float) cache.get( " MSFT " );
// Add another price to the Map, this should kick out the LRU item.
cache.put( " AA " , new Float( 203.20 ) );
System.out.println(cache.size()+"cscoPrice:"+(Float) cache.get( " CSCO " )
+"\tmsPrice:"+(Float) cache.get( " MSFT " )+"\t\ntscPrice:"+(Float) cache.get( " TSC " )
+"\tluPrice:"+(Float) cache.get( " LU " )+"\tpPrice:"+(Float) cache.get( " P " )
+"\tmsPrice2:"+(Float) cache.get( " MSFT " )+"\tAA:"+(Float) cache.get( " AA " ));
//return cache;
}
LRUMap的容量只设置为5,所以在第六个值插入的时候,会清除第一个get的数据
如果没有get操作,则第一个put的值会被清除