From 6468a92f3250b671a3228fe3c6dac85f3ea35d5e Mon Sep 17 00:00:00 2001 From: Evgeny Petrov Date: Mon, 16 Feb 2015 15:56:30 +0300 Subject: [PATCH] allow override diskCachePath --- SDWebImage/SDImageCache.h | 2 ++ SDWebImage/SDImageCache.m | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index 62894a156..8fae2bd7f 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -65,6 +65,8 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot */ - (id)initWithNamespace:(NSString *)ns; +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace; + /** * Add a read-only cache path to search for images pre-cached by SDImageCache * Useful if you want to bundle pre-loaded images with your app diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index dbc2d9695..70018d50c 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -74,8 +74,7 @@ - (id)initWithNamespace:(NSString *)ns { _memCache.name = fullNamespace; // Init the disk cache - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); - _diskCachePath = [paths[0] stringByAppendingPathComponent:fullNamespace]; + _diskCachePath = [self makeDiskCachePath:fullNamespace]; dispatch_sync(_ioQueue, ^{ _fileManager = [NSFileManager new]; @@ -144,6 +143,12 @@ - (NSString *)cachedFileNameForKey:(NSString *)key { #pragma mark ImageCache +// Init the disk cache +-(NSString *)makeDiskCachePath:(NSString*)fullNamespace{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + return [paths[0] stringByAppendingPathComponent:fullNamespace]; +} + - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk { if (!image || !key) { return;