[Go] Original
Android Glide Data Update and memory cache, hard disk cache cleanup
Solutions for this problem:
Solution 1:
From the cache key value provided by glide to the <K,V> structure model, overriding the cache's <K,V> key-value policy can avoid the resource update problem under the same resource address, but the implementation of this scheme is more complicated and not necessary. Not recommended, unless required.
Solution 2:
Glide.get (This). Clearmemory ();
Cleans up the in-memory cache.
Glide.get (This). Cleardiskcache ();
Clean the cache on the hard disk.
The above two methods clear the global memory cache and the hard disk cache, although can once and for all solve the cache caused the resource old problem, but will seriously affect the global performance, so use caution, unless it is in the whole app to do a brand new start or restore the original state, otherwise try to avoid using.
Solution 3 (Recommended):
The code is as follows:
[Java]View PlainCopy
- imageview image= (ImageView) findviewbyid (r.id.image);
- glide.with (this ). Load ( )
- .skipmemorycache (true )
- .diskcachestrategy (Diskcachestrategy.none)
- . into (image);
Key code: Skipmemorycache (True). Diskcachestrategy (Diskcachestrategy.none)
Skipmemorycache (true), skipping the memory cache.
Diskcachestrategy (Diskcachestrategy.none), do not cache in disk.
The combination of these two functions allows glide to discard the memory cache and the hard disk cache for this time, which is equivalent to a new request. This forces glide to initiate a completely new data load from the given resource address, rather than taking the cache from the old cache.
Appendix:
1, "Android image loading and caching open source framework: Android Glide" link: http://blog.csdn.net/zhangphil/article/details/45535693
2, "Android Glide loading pictures when converted to round, rounded, frosted glass and other picture effects" Link: http://blog.csdn.net/zhangphil/article/details/52806374
Android Glide Data Update and memory cache, hard disk cache cleanup