@Test public void evictionWithSingletonCache() { LruCache cache = new LruCache(1); cache.set("a", A); cache.set("b", B); assertSnapshot(cache, "b", B); }
@Override public void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); } int addedSize = Utils.getBitmapBytes(bitmap); if (addedSize > maxSize) { return; } synchronized (this) { putCount++; size += addedSize; Bitmap previous = map.put(key, bitmap); if (previous != null) { size -= Utils.getBitmapBytes(previous); } } trimToSize(maxSize); }
LruCache implements Cache { @Override public void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); } int addedSize = Utils.getBitmapBytes(bitmap); if (addedSize > maxSize) { return; } synchronized (this) { putCount++; size += addedSize; Bitmap previous = map.put(key, bitmap); if (previous != null) { size -= Utils.getBitmapBytes(previous); } } trimToSize(maxSize); } }
LruCache implements Cache { @Override public void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); } int addedSize = Utils.getBitmapBytes(bitmap); if (addedSize > maxSize) { return; } synchronized (this) { putCount++; size += addedSize; Bitmap previous = map.put(key, bitmap); if (previous != null) { size -= Utils.getBitmapBytes(previous); } } trimToSize(maxSize); } LruCache(@NonNull Context context);  LruCache(int maxSize); }
LruCache implements Cache { @Override public void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); } int addedSize = Utils.getBitmapBytes(bitmap); if (addedSize > maxSize) { return; } synchronized (this) { putCount++; size += addedSize; Bitmap previous = map.put(key, bitmap); if (previous != null) { size -= Utils.getBitmapBytes(previous); } } trimToSize(maxSize); } LruCache(@NonNull Context context);  LruCache(int maxSize); @Override Bitmap get(@NonNull String key); @Override void set(@NonNull String key, @NonNull Bitmap bitmap); final void evictAll(); @Override final synchronized int size(); @Override final synchronized int maxSize(); @Override final synchronized void clear(); @Override final synchronized void clearKeyUri(String uri); final synchronized int hitCount(); final synchronized int missCount(); final synchronized int putCount(); final synchronized int evictionCount(); }
LruCache implements Cache { @Override public void set(@NonNull String key, @NonNull Bitmap bitmap) { if (key == null || bitmap == null) { throw new NullPointerException("key == null || bitmap == null"); } int addedSize = Utils.getBitmapBytes(bitmap); if (addedSize > maxSize) { return; } synchronized (this) { putCount++; size += addedSize; Bitmap previous = map.put(key, bitmap); if (previous != null) { size -= Utils.getBitmapBytes(previous); } } trimToSize(maxSize); } LruCache(@NonNull Context context);  LruCache(int maxSize); @Override Bitmap get(@NonNull String key); @Override void set(@NonNull String key, @NonNull Bitmap bitmap); final void evictAll(); @Override final synchronized int size(); @Override final synchronized int maxSize(); @Override final synchronized void clear(); @Override final synchronized void clearKeyUri(String uri); final synchronized int hitCount(); final synchronized int missCount(); final synchronized int putCount(); final synchronized int evictionCount();  }