Skip to content
This repository

Know if the image has been retrieved from cache or not #181

CrazyKoala opened this Issue · 2 comments

3 participants

CrazyKoala Olivier Poitrey Diego Torres

Hey guys.

I am trying to figure out if there's a CHEAP way (in terms of processing time) to know if the picture was retrieved from cache (memory or disk).

This information (possibly a boolean) could be a very nice addition to have cause the post processing may be different afterwards.

This would apply to SetImageWithURL or downloadWithURL and possibly other alternatives to download the picture.

Would it be possible to receive such a boolean in the success block ?

Right now what I do is that I use queryimage to check if the image is available in cache or not. Although it does work there's a performance issue, the process seems to be quite costly.
On the iPhone4 and recent idevices, it remains sort of acceptable (still a bit borderline), but on iPhone3 devices, checking from the disk is really slow. Thus I only search for images in the memory cache.

I hope I made clear where I was coming from. My wild guess is that providing the boolean "imageFromCached" would be insignificant in terms of processing cost.

Thx for the help :)

Diego Torres

To do that, I checked the difference between the timestamp before the request and after, like this

CFAbsoluteTime aTime = CFAbsoluteTimeGetCurrent();
[UIImage setImage... success^(args) {
     CFAbsoluteTime anotherTime = CFAbsoluteTimeGetCurrent();
     if (anotherTime - aTime >= 0.03) {
           //NOT CACHE
     } else {


That's how i did it, the 0.03 diff I made it up (I don't remember how much it was), you should measure on device and see what fits.

Obviously, this is a partial solution and the BOOL should really be there;

Olivier Poitrey rs referenced this issue from a commit
Olivier Poitrey Add a cached parameter to the success block to tell the receiver if t…
…he image came from cache or network #181
Olivier Poitrey rs closed this

Great, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.