Glide in Android gets the cache size and clears the cached pictures

Clear glide cache

Glide has the function of clearing cache, corresponding to glide. Get (context). Cleardiskcache(); (clear disk cache) and glide. Get (context). Clearmemory(); (clear memory cache) two methods. The cleardiskcache () method must run on the child thread and the clearmemory () method must run on the main thread. These two methods are mandatory. See the source code for details

Gets the size of glide cache space

There have also been some introductions on the Internet, but the implementation code given has some problems, and I have made some modifications here. The following method is suitable for the case where glide is the default cache directory, whether internal storage space or external. Because we can use internalcachediskcachefactory.default_ DISK_ CACHE_ Dir and externalcachediskcachefactory.default_ DISK_ CACHE_ Dir obtains the folder names of internal and external storage cache folders, and obtains the paths of internal and external storage through context. Getcachedir() and context. Getexternalcachedir(). Then you can sum and clear all cache files by traversing the files in the folder. The following tool classes have been written by predecessors in other articles, but there are some known problems, Some changes have been made here

It can realize a function of clearing the picture cache. The effects in the application are as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>