Code example for ConcurrentHashMap

Methods: get, put

0
            } 
        } 
    } 
 
    private void cacheBitmapToMemory(final String url, final Bitmap bitmap) {
        memoryCache.put(getCacheKey(url), new SoftReference<Bitmap>(bitmap));
    } 
 
    private void cacheBitmapToDisk(final String url, final Bitmap bitmap) {
        writeThread.execute(new Runnable() {
            @Override 
            public void run() { 
                if(diskCacheEnabled) {
                    BufferedOutputStream ostream = null;
                    try { 
                        ostream = new BufferedOutputStream(new FileOutputStream(new File(diskCachePath, getCacheKey(url))), 2*1024);
                        bitmap.compress(CompressFormat.PNG, 100, ostream);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } finally { 
                        try { 
                            if(ostream != null) {
                                ostream.flush();
                                ostream.close();
                            } 
                        } catch (IOException e) {}
                    } 
                } 
            } 
        }); 
    } 
 
    private Bitmap getBitmapFromMemory(String url) {
        Bitmap bitmap = null;
        SoftReference<Bitmap> softRef = memoryCache.get(getCacheKey(url));
        if(softRef != null){
            bitmap = softRef.get();
        } 
 
        return bitmap;