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