Re: [iPhone] Caching images fetched from a URL?
Re: [iPhone] Caching images fetched from a URL?
- Subject: Re: [iPhone] Caching images fetched from a URL?
- From: Luke the Hiesterman <email@hidden>
- Date: Tue, 12 May 2009 14:22:06 -0700
On May 12, 2009, at 2:13 PM, Eric E. Dolecki wrote:
Okay, so I know I can somehow cache them... but I have some noob
questions.
- how do I cache the images themselves? Some binary data object
written to
the disk? How?
If you're caching to memory, all you really need to do is retain the
UIImage and keep a reference around so you can get to it later. To
cache to the disk, you could encode your UIImage to NSData using
NSKeyedArchiver, and then write to a file.
- how do I check if the image has already been loaded (check an
NSMutableArray populated with dictionaries with a url string and url
key?)
I would have the following keys in my dictionary:
1. URLKey
2. MemoryCacheReferenceKey - this contains a reference to a UIImage in
memory
3. FileReferenceKey - this contains a file path where the image can be
cached on disk.
- if I find that the image has been cached (somehow), how do I use
that
image instead?
Using the above dictionary scheme, I would first check if my
MemoryCacheReferenceKey is valid. If so, I use that UIImage and be
done. Otherwise, I would check for a file at the location in
FileReferenceKey and use that if it exists. If I don't find anything
in either of those caches, I would download the image using the URLKey.
Hope that helps.
Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden