bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.69k stars 6.13k forks source link

onlyRetrieveFromCache fails for custom ModelLoader #4455

Open wangtb opened 3 years ago

wangtb commented 3 years ago

Glide Version:4.11.0

Integration libraries:okhttp3-integration:4.11.0

Device/Android Version:Android 9.0, Sumsang S8

Issue details / Repro steps / Use case background:

  1. Load image from network if there is no local cache
  2. Load new image from network(same model, different signature), using cached image as placeholder

    Glide load line / GlideModule (if any) / list Adapter code (if any):

    GlideApp.with(mContext)
                .load(model)
                .signature(oldSignature)
                .onlyRetrieveFromCache(true)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target,
                                                boolean isFirstResource) {
                        GlideApp.with(mContext)
                                .load(model)
                                .placeholder(R.mipmap.default)
                                .error(R.mipmap.error)
                                .signature(oldSignature)
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .into(imageView);
                        return false;
                    }
    
                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target,
                                                   DataSource dataSource, boolean isFirstResource) {
                        GlideApp.with(mContext)
                                .load(model)
                                .placeholder(resource)
                                .error(resource)
                                .signature(newSignature)
                                .dontAnimate()
                                .diskCacheStrategy(DiskCacheStrategy.ALL)
                                .into(imageView);
                        return false;
                    }
                })
                .preload();

    But onLoadFailed was called all the time.

    Layout XML:

    <FrameLayout xmlns:android="...

Stack trace / LogCat:

W/Glide: Load failed for Model@57fa5b0 with size [-2147483648x-2147483648]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
sjudd commented 3 years ago

http://bumptech.github.io/glide/doc/debugging.html#unexpected-cache-misses