Iphone: Smart way to cache a large number of images?

I have a UITableView that displays hundreds of images downloaded from the Internet. Of course, I don’t want to store all the images in RAM - I need to create a small "cache" of images in RAM and write the images that I don’t need right now to the "disk". Of course, I do not want this mechanism to interfere with the user interface (reads too much and writes to disk / flash drive in the main stream). What is the best and easiest way to implement such a thing? Are there any open source projects that use such a thing I can look at?

+5
source share
3 answers

In the end, I used SDWebImage Very light and elegant.

+1
source

Browse the Three20 library, especially the TTURLRequest, TTURLCache, and TTImageView classes.

+1
source

I have a class that stores a UIImage in an NSMutableDictionary. If UIImage already exists in the dictionary, I simply return this object, and not create a new UIImage.


#import "Cache.h"
@implementation Cache

static NSMutableDictionary *dict;

+ (UIImage*)loadImageFromWeb:(NSString*)imageName{
    if (!dict) dict = [[NSMutableDictionary dictionary] retain];

    UIImage* image = [dict objectForKey:imageName];
    if (!image)
    {
        image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: imageName]]];
        if (image)
        {
            [dict setObject:image forKey:imageName];
        }
    }

    return image;
}

-1
source

All Articles