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