0

How would I go about finding out whether a UIImage has already been cached with NSURLConnection?

example:

if([NSURLCache containsObject:[UIImage imageNamed@"testPic.png"]]){
NSLog(@"item already cached!");
}

obviously the above code doesn't work but you get the point...

Thanks!

Praxder
  • 2,315
  • 4
  • 32
  • 51

1 Answers1

0

You have to save a copy of your request, then later ask the sharedCache:

- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request

The returned object has a bunch of stuff in it including the data object.

David H
  • 40,852
  • 12
  • 92
  • 138
  • Can you elaborate a little more or give me an example? – Praxder Aug 08 '12 at 04:48
  • Its just as I said. When you do a NSURLConnection, save the NSURLRequest in an ivar. Then later you can ask the NSURLCache for a cached response. If you get an object back, then ask it for its data (if that is what you want) "NSData *data = [cachedResponse data];" The class description for NSCachedURLResponse has other properties you can request too. – David H Aug 08 '12 at 11:21