Asynchronous image downloader with cache support as a UIImageView category
Go to file
Olivier Poitrey 891b957ba8 Add some example about using downloader and image cache store components independently + general doc enhancement 2009-09-21 04:46:34 +02:00
DMImageCache.h Split DMWebImageDownloader from DMWebImageView, and refactor so each class maintain its own operation 2009-09-21 03:45:04 +02:00
DMImageCache.m Split DMWebImageDownloader from DMWebImageView, and refactor so each class maintain its own operation 2009-09-21 03:45:04 +02:00
DMWebImageDownloader.h Remove unnecessary coupling between DMWebImageDownloader and DMImageCache 2009-09-21 04:03:02 +02:00
DMWebImageDownloader.m Remove unnecessary coupling between DMWebImageDownloader and DMImageCache 2009-09-21 04:03:02 +02:00
DMWebImageView.h Remove unnecessary coupling between DMWebImageDownloader and DMImageCache 2009-09-21 04:03:02 +02:00
DMWebImageView.m Remove unnecessary coupling between DMWebImageDownloader and DMImageCache 2009-09-21 04:03:02 +02:00
LICENSE Add licensing information 2009-09-19 22:24:03 +02:00
README.md Add some example about using downloader and image cache store components independently + general doc enhancement 2009-09-21 04:46:34 +02:00

README.md

Dailymotion Web Image

This library provides a drop-in remplacement for UIImageVIew with support for remote images coming from the web.

It provides:

  • Drop-in replacement to UIImageView
  • Asynchronous image downloader
  • Asynchronous memory + disk image caching with automatic cache expiration handling

How To Use It

DMWebImageView as UIImageWeb Drop-In Replacement

Most common use is in conjunction with an UITableView:

  • Place an UIImageView as a subview of your UITableViewCell in Interface Builder
  • Set its class to DMImageView in the identity panel.
  • Optionally set an image from your bundle to this UIImageView, it will be used as a placeholder image waiting for the real image to be downloaded.
  • In your tableView:cellForRowAtIndexPath: UITableViewDataSource method, invoke the setImageWithURL: method of the DMWebImage view with the URL of the image to download

Your done, everything will be handled for you, from parallel downloads to caching management.

Asynchronous Image Downloader

It is possible to use the NSOperation based image downloader independently. Just create an instance of DMWebImageDownloader using its convenience constructor downloaderWithURL:target:action:.

DMWebImageDownloader *downloader = [DMWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)];

The download will by queued immediately and the downloadFinishedWithImage: method will be called as soon as the download of image will be completed (prepare not to be called from the main thread).

Asynchronous Image Caching

It is also possible to use the NSOperation based image cache store independently. DMImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn't add unnecessary latency to the UI.

The DMImageCache class provides a singleton instance for convenience but you can create your own instance if you want to create separated cache namespaces.

To lookup the cache, you use the imageForKey: method. If the method returns nil, it means the cache doesn't currently own the image. You are thus responsible of generating and caching it. The cache key is an application unique identifier for the image to cache. It is generally the absolute URL of the image.

UIImage *myCachedImage = [[DMImageCache sharedImageCache] imageFromKey:myCacheKey];

By default DMImageCache will lookup the disk cache if an image can't be found in the memory cache. You can prevent this from happening by calling the alternative method imageFromKey:fromDisk: with a negative second argument.

To store an image into the cache, you use the storeImage:forKey: method:

[[DMImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey];

By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative third argument.

Future Enhancements

  • Easy way to use it with default UITableView styles without requiring to create a custom UITableViewCell
  • LRU memory cache cleanup instead of reset on memory warning