views:

416

answers:

2

hello,

I'm developing an app that needs to cache some images from the web the images are likely to be 100x100

I just need to know which is better:

  1. Store the images as files in the iPhone file system
  2. Store them as blob in a sqlite Db along with other data already saved on the database.

Appreciate your help.

A: 

From past experience, storing (and retrieving) images from the file system should be a bit faster than from the DB. As for ease of handling and maintenance it only depends on what you're more familiar with: SQL scripts or iphoneOS file system functions.

MihaiD
+4  A: 

Storing images in the database is definitely not recommended by Apple, the filesystem is actually really good at locating files (images in this case) on the disk, which makes it the best solution for saving images. These were the exact same words an Apple technology evangelist used in the iPhone Tech Talk World Tour in Paris. If it are only a few images, you might get away with it, but when the number can potentially become quite large, files is the way to go.

Besides, you can use the lazy loading methods to grab the images of the disk, this will delay loading the image from disk to when it really is needed.

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.png"]]

Edit: imageWithContentsOfFile does not load the image at once, thus not locking the thread, neither does it cache the image. The other method imageNamed: does lock the thread and loads the image at once, on the bright side, it does cache the image.

Yannick Compernol
Are you sure imageWithContentsOfFile does lazy loading? The documentation doesn't say anything about that.
MihaiD
One of the sessions on the iPhone Tech Talk talked about performance, this was one of the points they talked about.
Yannick Compernol
100% agree, don't store images in the DB. I did at 1st and then moved to using the filesystem later to see if it'd improve performance and boy did it ever.
Shizam