Want more features on Pastebin? Sign Up, it's FREE!
Guest

MemoryCache

By: a guest on Mar 18th, 2013  |  syntax: None  |  size: 0.70 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data