Glide: Is there any way to know if image is cached in disk before onResourceReady

Created on 20 Jun 2017  路  9Comments  路  Source: bumptech/glide

I have a home screen and there is a wallpaper that displayed in the background as default.
When launch the app I check with an URL to retrieve the latest wallpaper. I want to just show the latest wallpaper if is cached without showing the default first. I do the check in listener's onResourceReady but it seems to hit the URL if there is no cached image, which causes a white background shown for a short period of time before image is retrieved from the internet. Is there any way to quickly check if the image cached in disk so I can determine if to show the default first? Thanks.

I am using 4.0

question v4

Most helpful comment

onlyRetrieveFromCache(true) + a listener()/custom target?

All 9 comments

onlyRetrieveFromCache(true) + a listener()/custom target?

@TWiStErRob
Yes it works !! The only thing is that I have to instantiate an RequestOptions. Thought I can just call .apply(RequestOptions.onlyRetrieveFromCache()).
Thank you anyway.

You can cache that option in a static constant (you can freeze it as well I think to prevent modification).

Also look at http://bumptech.github.io/glide/doc/generatedapi.html

4.0.0-RC1 can't work with .apply(RequestOptions.onlyRetrieveFromCache())

RequestOptions have no static method onlyRetrieveFromCache.

how can I do with v4?

Note that if you do this, you'll get "Load failed" log messages at WARN priority. I don't believe there's a way to disable those, short of setting the Glide log level to ERROR or above, as per http://bumptech.github.io/glide/doc/configuration.html#log-level.

Incidentally, for people who are having trouble finding it, you want .apply(new RequestOptions().onlyRetrieveFromCache(true)).

In case of cache miss, would the error listener/target be invoked synchronously?

onlyRetrieveFromCache(true) + a listener()/custom target?

can you please give example how to attach custom target

is there any synchronous method to check if image exists in cache please help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sant527 picture sant527  路  3Comments

Tryking picture Tryking  路  3Comments

Anton111111 picture Anton111111  路  3Comments

kenneth2008 picture kenneth2008  路  3Comments

r4m1n picture r4m1n  路  3Comments