1 package com.ibm.icu.impl; 2 3 import java.lang.ref.SoftReference ; 4 import java.util.Collections ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 public class SimpleCache implements ICUCache { 9 10 public Object get(Object key) { 11 SoftReference ref = cacheRef; 12 if (ref != null) { 13 Map map = (Map )ref.get(); 14 if (map != null) { 15 return map.get(key); 16 } 17 } 18 return null; 19 } 20 21 public void put(Object key, Object value) { 22 SoftReference ref = cacheRef; 23 Map map = null; 24 if (ref != null) { 25 map = (Map )ref.get(); 26 } 27 if (map == null) { 28 map = Collections.synchronizedMap(new HashMap ()); 29 ref = new SoftReference (map); 30 cacheRef = ref; 31 } 32 map.put(key, value); 33 } 34 35 public void clear() { 36 cacheRef = null; 37 } 38 39 private SoftReference cacheRef = null; 40 } 41 | Popular Tags |