diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-02-10 13:50:24 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-02-10 13:50:24 -0800 |
commit | 34895b09db3679c7d4e80d21198847d316e6b0c3 (patch) | |
tree | 7197f3103b6747ebd7e8a3a8db9cb54af1992a03 /core/java/android/util | |
parent | 83a7b963f0070022d98853ea1fb4fa5c81cc5e79 (diff) | |
download | frameworks_base-34895b09db3679c7d4e80d21198847d316e6b0c3.zip frameworks_base-34895b09db3679c7d4e80d21198847d316e6b0c3.tar.gz frameworks_base-34895b09db3679c7d4e80d21198847d316e6b0c3.tar.bz2 |
Document that LruCache is threadsafe.
Change-Id: Iae1421b8c768000e56806f6cd74aef7c69a78973
http://b/3184897
Diffstat (limited to 'core/java/android/util')
-rw-r--r-- | core/java/android/util/LruCache.java | 22 |
1 files changed, 15 insertions, 7 deletions
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. * * <p>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: * <pre> {@code - * int cacheSize = 4 * 1024 * 1024; // 4MiB - * LruCache<String, Bitmap> bitmapCache = new LruCache<String, Bitmap>(cacheSize) { - * protected int sizeOf(String key, Bitmap value) { - * return value.getByteCount(); + * int cacheSize = 4 * 1024 * 1024; // 4MiB + * LruCache<String, Bitmap> bitmapCache = new LruCache<String, Bitmap>(cacheSize) { + * protected int sizeOf(String key, Bitmap value) { + * return value.getByteCount(); + * } + * }}</pre> + * + * <p>This class is thread-safe. Perform multiple cache operations atomically by + * synchronizing on the cache: <pre> {@code + * synchronized (cache) { + * if (cache.get(key) == null) { + * cache.put(key, value); * } - * }}</pre> + * }}</pre> */ public class LruCache<K, V> { private final LinkedHashMap<K, V> map; |