search

Home  >  Q&A  >  body text

android - 关于glide+recyclerview默认读取缓存

如上问题,关于glide+recyclerview默认读取缓存,导致刷新时,即使对方更新了头像但是url还是原来url,就会去默认读取缓存,设置signature后,问题是解决了,但接着每次都会去刷新头像,缓存的意义就没有了,求解!

 Glide.with(context)
            .load(uri)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .crossFade()
            .signature(new StringSignature(UUID.randomUUID().toString()))
            .into(view);
PHPzPHPz2772 days ago494

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:46:58

    If you want to get a new avatar only after the user updates the image, the key issue is to let the app know that the image cache corresponding to the url is invalid.
    So you should start with the relevant parameters cached in the header of the response returned by the url.

    If you are using an interface provided by a third party, you have no choice but to choose whether to update the image every time without caching, or to compromise and update it every once in a while.
    If you can modify the interface for obtaining avatars, It is recommended that the person who writes the interface add cache information to invalidate the client cache when updating the avatar.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:46:58

    Glide decides to load the cache or re-request based on the URL. If your URL remains unchanged but the image content changes quickly, it is best to disable the cache

    .skipMemoryCache( true )
    .diskCacheStrategy( DiskCacheStrategy.NONE )
    

    reply
    0
  • Cancelreply