Eric,

I think one of the more effective ways to cache images is to store your image to the file system, and then store meta-data for that image in a local SQL database. That meta-data should include a "last updated" date for the image. Then, instead of requesting the image directly from the server, first request its meta-data from the server, which will return meta-data indicating if the image has been updated on the server or not. If it has, download the new image, write it to your local file system, and update the meta-data in your local SQL database. If not, just continue to use the existing local image.

I don't know what sizes your images are, or how many you are processing at once, but if you are going to try to construct an in- memory cache for the images mentioned, make SURE you pay close attention to the

- (void)didReceiveMemoryWarning

method and manage your cache accordingly should that method get called. Otherwise, what might appear as a wonderful optimization may end up being an effective means to crash your app.

I hope that helps.

Brad

On May 12, 2009, at 2:22 PM, Luke the Hiesterman wrote:


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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/brado%40bighillsoftware.com

This email sent to br...@bighillsoftware.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to