summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Kung <kingkung@google.com>2014-01-14 14:34:42 -0800
committerJames Kung <kingkung@google.com>2014-01-14 14:42:50 -0800
commita07e0af0f1997ce3d40df6a8a9f44cb0b2e4c07f (patch)
tree602af3541d05d2b34357cde74a8454ae57bd2570
parentad6ca3f895022ded1a11f3eedc50d70ea90cd4da (diff)
downloadbitmap-a07e0af0f1997ce3d40df6a8a9f44cb0b2e4c07f.tar.gz
Store null results in the cache
Change-Id: I034fa56a8c646a65781236fe832c0f54d9f86984
-rw-r--r--src/com/android/bitmap/DecodeTask.java4
-rw-r--r--src/com/android/bitmap/UnrefedPooledCache.java9
2 files changed, 10 insertions, 3 deletions
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<Void, Void, ReusableBitmap> {
} 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<K, V extends Poolable> implements PooledCache<K,
@Override
public V put(K key, V value) {
Trace.beginSection("cache put");
+ // Null values not supported.
+ if (value == null) {
+ return null;
+ }
synchronized (mCache) {
final V prev;
if (value.isEligibleForPooling()) {