From 34895b09db3679c7d4e80d21198847d316e6b0c3 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 10 Feb 2011 13:50:24 -0800 Subject: Document that LruCache is threadsafe. Change-Id: Iae1421b8c768000e56806f6cd74aef7c69a78973 http://b/3184897 --- core/java/android/util/LruCache.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'core/java/android/util') diff --git a/core/java/android/util/LruCache.java b/core/java/android/util/LruCache.java index b85bf39..d995232 100644 --- a/core/java/android/util/LruCache.java +++ b/core/java/android/util/LruCache.java @@ -34,15 +34,23 @@ import java.util.Map; * assume a value will always be returned, even when there's a cache miss. * *

By default, the cache size is measured in the number of entries. Override - * {@link #sizeOf} to size the cache in different units. For, this cache is - * limited to 4MiB of bitmaps: + * {@link #sizeOf} to size the cache in different units. For example, this cache + * is limited to 4MiB of bitmaps: *

   {@code
- * int cacheSize = 4 * 1024 * 1024; // 4MiB
- * LruCache bitmapCache = new LruCache(cacheSize) {
- *     protected int sizeOf(String key, Bitmap value) {
- *         return value.getByteCount();
+ *   int cacheSize = 4 * 1024 * 1024; // 4MiB
+ *   LruCache bitmapCache = new LruCache(cacheSize) {
+ *       protected int sizeOf(String key, Bitmap value) {
+ *           return value.getByteCount();
+ *       }
+ *   }}
+ * + *

This class is thread-safe. Perform multiple cache operations atomically by + * synchronizing on the cache:

   {@code
+ *   synchronized (cache) {
+ *     if (cache.get(key) == null) {
+ *         cache.put(key, value);
  *     }
- * }}
+ * }} */ public class LruCache { private final LinkedHashMap map; -- cgit v1.1