Skip to content

Commit

Permalink
Remove Dailymotion paternity and move to joined paternity with Fraggl…
Browse files Browse the repository at this point in the history
…e behind the Simple Design (SD) team name
  • Loading branch information
Olivier Poitrey committed Sep 21, 2009
1 parent 8370d5d commit a7734af
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2009 Dailymotion - Olivier Poitrey <[email protected]>
Copyright (c) 2009 Olivier Poitrey <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ it, et voila!
How To Use It
-------------

### DMWebImageView as UIImageWeb Drop-In Replacement
### SDWebImageView 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.
- Set its class to SDImageView 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
method of the SDWebImage 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:.
of SDWebImageDownloader using its convenience constructor downloaderWithURL:target:action:.

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

Expand All @@ -85,27 +85,27 @@ soon as the download of image will be completed (prepare not to be called from t

### Asynchronous Image Caching

It is also possible to use the NSOperation based image cache store independently. DMImageCache
It is also possible to use the NSOperation based image cache store independently. SDImageCache
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
The SDImageCache 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];
UIImage *myCachedImage = [[SDImageCache sharedImageCache] imageFromKey:myCacheKey];

By default DMImageCache will lookup the disk cache if an image can't be found in the memory cache.
By default SDImageCache 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];
[[SDImageCache 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
Expand Down
8 changes: 4 additions & 4 deletions DMImageCache.h → SDImageCache.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <Foundation/Foundation.h>

@interface DMImageCache : NSObject
@interface SDImageCache : NSObject
{
NSMutableDictionary *memCache;
NSString *diskCachePath;
NSOperationQueue *cacheInQueue;
}

+ (DMImageCache *)sharedImageCache;
+ (SDImageCache *)sharedImageCache;
- (void)storeImage:(UIImage *)image forKey:(NSString *)key;
- (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
- (UIImage *)imageFromKey:(NSString *)key;
Expand Down
14 changes: 7 additions & 7 deletions DMImageCache.m → SDImageCache.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "DMImageCache.h"
#import "SDImageCache.h"
#import <CommonCrypto/CommonDigest.h>

static NSInteger cacheMaxCacheAge = 60*60*24*7; // 1 week

static DMImageCache *instance;
static SDImageCache *instance;

@implementation DMImageCache
@implementation SDImageCache

#pragma mark NSObject

Expand Down Expand Up @@ -81,11 +81,11 @@ - (void)willTerminate

#pragma mark ImageCache (class methods)

+ (DMImageCache *)sharedImageCache
+ (SDImageCache *)sharedImageCache
{
if (instance == nil)
{
instance = [[DMImageCache alloc] init];
instance = [[SDImageCache alloc] init];
}

return instance;
Expand Down
6 changes: 3 additions & 3 deletions DMWebImageDownloader.h → SDWebImageDownloader.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <Foundation/Foundation.h>

@interface DMWebImageDownloader : NSOperation
@interface SDWebImageDownloader : NSOperation
{
NSURL *url;
id target;
Expand Down
10 changes: 5 additions & 5 deletions DMWebImageDownloader.m → SDWebImageDownloader.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "DMWebImageDownloader.h"
#import "SDWebImageDownloader.h"

static NSOperationQueue *downloadQueue;

@implementation DMWebImageDownloader
@implementation SDWebImageDownloader

@synthesize url, target, action;

Expand All @@ -22,7 +22,7 @@ - (void)dealloc

+ (id)downloaderWithURL:(NSURL *)url target:(id)target action:(SEL)action
{
DMWebImageDownloader *downloader = [[[DMWebImageDownloader alloc] init] autorelease];
SDWebImageDownloader *downloader = [[[SDWebImageDownloader alloc] init] autorelease];
downloader.url = url;
downloader.target = target;
downloader.action = action;
Expand Down
10 changes: 5 additions & 5 deletions DMWebImageView.h → SDWebImageView.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <UIKit/UIKit.h>

@class DMWebImageDownloader;
@class SDWebImageDownloader;

@interface DMWebImageView : UIImageView
@interface SDWebImageView : UIImageView
{
UIImage *placeHolderImage;
DMWebImageDownloader *downloader;
SDWebImageDownloader *downloader;
}

- (void)setImageWithURL:(NSURL *)url;
Expand Down
18 changes: 9 additions & 9 deletions DMWebImageView.m → SDWebImageView.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
* This file is part of the DMWebImage package.
* (c) Dailymotion - Olivier Poitrey <[email protected]>
* This file is part of the SDWebImage package.
* (c) Olivier Poitrey <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "DMWebImageView.h"
#import "DMImageCache.h"
#import "DMWebImageDownloader.h"
#import "SDWebImageView.h"
#import "SDImageCache.h"
#import "SDWebImageDownloader.h"

@implementation DMWebImageView
@implementation SDWebImageView

- (void)dealloc
{
Expand Down Expand Up @@ -41,15 +41,15 @@ - (void)setImageWithURL:(NSURL *)url
self.image = placeHolderImage;
}

UIImage *cachedImage = [[DMImageCache sharedImageCache] imageFromKey:[url absoluteString]];
UIImage *cachedImage = [[SDImageCache sharedImageCache] imageFromKey:[url absoluteString]];

if (cachedImage)
{
self.image = cachedImage;
}
else
{
downloader = [[DMWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)] retain];
downloader = [[SDWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)] retain];
}
}

Expand All @@ -59,7 +59,7 @@ - (void)downloadFinishedWithImage:(UIImage *)anImage
self.image = anImage;

// Store the image in the cache
[[DMImageCache sharedImageCache] storeImage:anImage forKey:[downloader.url absoluteString]];
[[SDImageCache sharedImageCache] storeImage:anImage forKey:[downloader.url absoluteString]];

// Free the downloader
[downloader release];
Expand Down

0 comments on commit a7734af

Please sign in to comment.