Replaces #1398 Allow to customise cache and image downloader instances used with SDWebImageManager - added a new initializer (`initWithCache:downloader:`)
This commit is contained in:
parent
e6e5c5156b
commit
86fc47bf7b
|
@ -181,6 +181,12 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
*/
|
||||
+ (SDWebImageManager *)sharedManager;
|
||||
|
||||
/**
|
||||
* Allows to specify instance of cache and image downloader used with image manager.
|
||||
* @return new instance of `SDWebImageManager` with specified cache and downloader.
|
||||
*/
|
||||
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader;
|
||||
|
||||
/**
|
||||
* Downloads the image at the given URL if not present in cache or return the cached version otherwise.
|
||||
*
|
||||
|
|
|
@ -37,20 +37,22 @@
|
|||
return instance;
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
- (instancetype)init {
|
||||
SDImageCache *cache = [SDImageCache sharedImageCache];
|
||||
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
|
||||
return [self initWithCache:cache downloader:downloader];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCache:(SDImageCache *)cache downloader:(SDWebImageDownloader *)downloader {
|
||||
if ((self = [super init])) {
|
||||
_imageCache = [self createCache];
|
||||
_imageDownloader = [SDWebImageDownloader sharedDownloader];
|
||||
_imageCache = cache;
|
||||
_imageDownloader = downloader;
|
||||
_failedURLs = [NSMutableSet new];
|
||||
_runningOperations = [NSMutableArray new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (SDImageCache *)createCache {
|
||||
return [SDImageCache sharedImageCache];
|
||||
}
|
||||
|
||||
- (NSString *)cacheKeyForURL:(NSURL *)url {
|
||||
if (self.cacheKeyFilter) {
|
||||
return self.cacheKeyFilter(url);
|
||||
|
|
Loading…
Reference in New Issue