From a07e0af0f1997ce3d40df6a8a9f44cb0b2e4c07f Mon Sep 17 00:00:00 2001 From: James Kung Date: Tue, 14 Jan 2014 14:34:42 -0800 Subject: Store null results in the cache Change-Id: I034fa56a8c646a65781236fe832c0f54d9f86984 --- src/com/android/bitmap/DecodeTask.java | 4 +++- src/com/android/bitmap/UnrefedPooledCache.java | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'src/com') diff --git a/src/com/android/bitmap/DecodeTask.java b/src/com/android/bitmap/DecodeTask.java index 03b8445..e227446 100644 --- a/src/com/android/bitmap/DecodeTask.java +++ b/src/com/android/bitmap/DecodeTask.java @@ -439,9 +439,11 @@ public class DecodeTask extends AsyncTask { } catch (IOException ignored) { } } + + // Put result in cache, regardless of null. The cache will handle null results. + mCache.put(mKey, result); if (result != null) { result.acquireReference(); - mCache.put(mKey, result); if (DEBUG) { Log.d(TAG, "placed result in cache: key=" + mKey + " bmp=" + result + " cancelled=" + isCancelled()); diff --git a/src/com/android/bitmap/UnrefedPooledCache.java b/src/com/android/bitmap/UnrefedPooledCache.java index 50d793f..882dfea 100644 --- a/src/com/android/bitmap/UnrefedPooledCache.java +++ b/src/com/android/bitmap/UnrefedPooledCache.java @@ -16,10 +16,11 @@ package com.android.bitmap; -import com.android.bitmap.util.Trace; - import android.util.Log; import android.util.LruCache; + +import com.android.bitmap.util.Trace; + import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.LinkedBlockingQueue; @@ -86,6 +87,10 @@ public class UnrefedPooledCache implements PooledCache