package com.easemob.easeui.oss; import android.graphics.Bitmap; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; public class MemoryCache { // ���Ļ����� private static final int MAX_CACHE_CAPACITY = 30; private HashMap> mCacheMap = new LinkedHashMap>() { private static final long serialVersionUID = 1L; protected boolean removeEldestEntry( Entry> eldest){ return size() > MAX_CACHE_CAPACITY;}; }; public Bitmap get(String id){ if(!mCacheMap.containsKey(id)) return null; SoftReference ref = mCacheMap.get(id); return ref.get(); } public void put(String id, Bitmap bitmap){ mCacheMap.put(id, new SoftReference(bitmap)); } public void clear() { try { for(Map.Entry>entry :mCacheMap.entrySet()) { SoftReference sr = entry.getValue(); if(null != sr) { Bitmap bmp = sr.get(); if(null != bmp) bmp.recycle(); } } mCacheMap.clear(); } catch (Exception e) { e.printStackTrace();} } }