Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34895b09 authored by Jesse Wilson's avatar Jesse Wilson
Browse files

Document that LruCache is threadsafe.

Change-Id: Iae1421b8c768000e56806f6cd74aef7c69a78973
http://b/3184897
parent 83a7b963
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ 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) {
@@ -43,6 +43,14 @@ import java.util.Map;
 *           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>
 */
public class LruCache<K, V> {
    private final LinkedHashMap<K, V> map;