Android Glide Data Update and memory cache, hard disk cache cleanup

Source: Internet
Author: User

[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
  1. imageview image=  (ImageView)  findviewbyid (r.id.image);   
  2.         glide.with (this ). Load ( )   
  3.                  .skipmemorycache (true )   
  4.                  .diskcachestrategy (Diskcachestrategy.none)   
  5. . 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.