MemoryCache.java revision e743a1f03f24e33270f38de883b508d4312a7f69
1package com.bumptech.glide.load.engine.cache; 2 3import android.content.ComponentCallbacks2; 4import com.bumptech.glide.load.Key; 5import com.bumptech.glide.Resource; 6 7/** 8 * An interface for adding and removing resources from an in memory cache 9 */ 10public interface MemoryCache { 11 /** 12 * An interface that will be called whenever a bitmap is removed from the cache. 13 */ 14 public interface ResourceRemovedListener { 15 public void onResourceRemoved(Resource removed); 16 } 17 18 /** 19 * Adjust the maximum size of the cache by multiplying the original size of the cache by the given multiplier. 20 * 21 * <p> 22 * If the size multiplier causes the size of the cache to be decreased, items will be evicted until the cache 23 * is smaller than the new size. 24 * </p> 25 * 26 * @param multiplier A size multiplier >= 0. 27 */ 28 public void setSizeMultiplier(float multiplier); 29 30 /** 31 * Removes the value for the given key and returns it if present or null otherwise. 32 * @param key The key. 33 */ 34 public Resource remove(Key key); 35 36 /** 37 * Add bitmap to the cache with the given key 38 * @param key The key to retrieve the bitmap 39 * @param resource The {@link Resource} to store 40 * @return The old value of key (null if key is not in map) 41 */ 42 public Resource put(Key key, Resource resource); 43 44 /** 45 * Set the listener to be called when a bitmap is removed from the cache 46 * @param listener The listener 47 */ 48 public void setResourceRemovedListener(ResourceRemovedListener listener); 49 50 /** 51 * Evict all items from the memory cache. 52 */ 53 public void clearMemory(); 54 55 /** 56 * Trim the memory cache to the appropriate level. Typically called on the callback onTrimMemory. 57 * @param level This integer represents a trim level as specified in {@link ComponentCallbacks2} 58 */ 59 public void trimMemory(int level); 60} 61