1. package satellite.eclipse.imagedl;
  2.  
  3. import java.lang.ref.SoftReference;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import android.graphics.Bitmap;
  8.  
  9. public class MemoryCache {
  10. private Map<String, SoftReference<Bitmap>> cache=Collections.synchronizedMap(new HashMap<String, SoftReference<Bitmap>>());
  11.  
  12. public Bitmap get(String id){
  13. if(!cache.containsKey(id))
  14. return null;
  15. SoftReference<Bitmap> ref=cache.get(id);
  16. return ref.get();
  17. }
  18.  
  19. public void put(String id, Bitmap bitmap){
  20. cache.put(id, new SoftReference<Bitmap>(bitmap));
  21. }
  22.  
  23. public void clear() {
  24. cache.clear();
  25. }
  26. }