Merge pull request #498 from donholly/master
Added and exposed some methods that allow to check if an image exists on...
This commit is contained in:
commit
9820cafe9b
|
@ -159,4 +159,9 @@ typedef enum SDImageCacheType SDImageCacheType;
|
|||
*/
|
||||
- (void)calculateSizeWithCompletionBlock:(void (^)(NSUInteger fileCount, unsigned long long totalSize))completionBlock;
|
||||
|
||||
/**
|
||||
* Check if image exists in cache already
|
||||
*/
|
||||
- (BOOL)diskImageExistsWithKey:(NSString *)key;
|
||||
|
||||
@end
|
||||
|
|
|
@ -25,7 +25,9 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
@end
|
||||
|
||||
|
||||
@implementation SDImageCache
|
||||
@implementation SDImageCache {
|
||||
NSFileManager *_fileManager;
|
||||
}
|
||||
|
||||
+ (SDImageCache *)sharedImageCache
|
||||
{
|
||||
|
@ -60,6 +62,11 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
_diskCachePath = [paths[0] stringByAppendingPathComponent:fullNamespace];
|
||||
|
||||
dispatch_sync(_ioQueue, ^
|
||||
{
|
||||
_fileManager = NSFileManager.new;
|
||||
});
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
// Subscribe to app events
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
|
@ -184,6 +191,17 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
[self storeImage:image imageData:nil forKey:key toDisk:toDisk];
|
||||
}
|
||||
|
||||
- (BOOL)diskImageExistsWithKey:(NSString *)key
|
||||
{
|
||||
__block BOOL exists = NO;
|
||||
dispatch_sync(_ioQueue, ^
|
||||
{
|
||||
exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]];
|
||||
});
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
- (UIImage *)imageFromMemoryCacheForKey:(NSString *)key
|
||||
{
|
||||
return [self.memCache objectForKey:key];
|
||||
|
|
|
@ -171,4 +171,9 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
|
|||
*/
|
||||
- (BOOL)isRunning;
|
||||
|
||||
/**
|
||||
* Check if image has already been cached
|
||||
*/
|
||||
- (BOOL)diskImageExistsForURL:(NSURL *)url;
|
||||
|
||||
@end
|
||||
|
|
|
@ -66,6 +66,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)diskImageExistsForURL:(NSURL *)url
|
||||
{
|
||||
NSString *key = [self cacheKeyForURL:url];
|
||||
return [self.imageCache diskImageExistsWithKey:key];
|
||||
}
|
||||
|
||||
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
|
||||
{
|
||||
// Invoking this method without a completedBlock is pointless
|
||||
|
|
Loading…
Reference in New Issue