Question: Hi i have high resolution image in local(document). Now i want to list all local images in thumb nail size. I am using UICollectionView to show image while loading resize the image from high resolution to thumbnail. So scrolling speed lack in collectionView. Now i have confusion with how can i cache that resized thumbnail images. which one is the best option to do that. I have used SDWebimages to download and cached images from web. Thank you

```
 - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {

    //    NSLog(@"%i path", indexPath.row);
        CollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];
        ImageData *imgData =  [self readFromLocal:indexpath.item];
        UIImage *thumb = [self resizeImgToTumb:imgData.image];
        [cell.imgView setimage:thumg];

return cell;
}

```

Answer: 
I recommend storing the images on the file system in app-specific storage and reading those files when necessary. Use the [NSFileManager](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/nsfilemanager_Class/Reference/Reference.html) class to accomplish this. Be sure you write code to clean up any files you create so that they don't take up too much space on the user's device.

```
UIImage *image = ...;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *rootDirectory = [NSSearchPathForDirectoriesInDomain(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *imagePath = [rootDirectory stringByAppendingPathComponent:@"filename.png"];
NSError *error;

[imageData writeToFile:imagePath options:NSDataWritingAtomic error:&error];

```
If you are not completely worried about memory consumption you can create an NSDictionary and add your resized image to that. You will need to remove the objects from the dictionary once they are far enough off screen to be reloaded later.

```
[dictionary setObject:yourSmallImage forKey:indexPath];

```

Then retrieve it later:

```
UIImage *image = [dictionary objectForKey:indexPath];
if(!image)
{
    //Load it from your source, no cache found
}

```