Glide is divided into four levels of cache, respectively activecache, memoryCache, Diskdatacache, diskResourcecache. Activecache is an activecache that caches images in use. Memorycache is a memorycache. Diskdatacache is the original image cache for disk cache. Diskresourcecache is the post-processing image cache for disk cache. The first two are in-memory caches, and the last two are in-disk caches.

Activecache is a user-facing cache that is maintained by weak references and then stored in a HashMap.

Obtain: When APP needs to request a picture, it will first query it from the cache according to key. If it can obtain the image, add acquire to the number of times of reference of the image, and show the obtained image to the user.

Clear: The onRelease () method is called to release the image from activecache when the user slides the page and the image becomes invisible or the page is destroyed by calling onDestroy. If acquire<=0 indicates that the current page no longer refers to the image, then the image will be removed from activecache and stored in memoryCache.

Storage: When a user requests an image, if it is not obtained in the four-level cache, a network request will be made. After the request is successful, the image will be cached in activecache.

Memorycache: If the user requests an image that is not found in activecache, the search continues in memoryCache. If the image is found, the image is returned and deleted in memroryCache, but before returning, the image reference Acquire + 1 is given to record the image reference times, and the image is put into activecache. This level of memory cache utilizes the principle of Lrucache. If the cache is full, use the least used algorithm to clear the least commonly used images (acquire clear according to the number of images referenced).

For disk caching, you can set the parameters as required: Call diskCacheStrategy(diskCacheStrategy. NONE) Where there are four parameters: all, NONE, data, resource, and autonatic. All: indicates that both the original image and the converted image are cached. None: Disk caching is not performed. Data: cache only raw images; Resource: only cached images after conversion; Automatic: the default policy. If remote images are used, only the original images are cached. If the image is local, only the converted image is cached. Based on the above summary, there are only two types of disk caching in general: 1. Raw image caching, 2. Image cache after processing. And the two can be mixed. The bottom principle is made with DiskLruCache.