Authored by Bogdan Poplauschi

Merge pull request #1153 from LukeDurrant/CustomDiskCachePath

Custom disk cache path
@@ -76,6 +76,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot @@ -76,6 +76,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
76 */ 76 */
77 - (id)initWithNamespace:(NSString *)ns; 77 - (id)initWithNamespace:(NSString *)ns;
78 78
  79 +/**
  80 + * Init a new cache store with a specific namespace and directory
  81 + *
  82 + * @param ns The namespace to use for this cache store
  83 + * @param directory Directory to cache disk images in
  84 + */
  85 +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;
  86 +
79 -(NSString *)makeDiskCachePath:(NSString*)fullNamespace; 87 -(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
80 88
81 /** 89 /**
@@ -84,6 +84,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { @@ -84,6 +84,11 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
84 } 84 }
85 85
86 - (id)initWithNamespace:(NSString *)ns { 86 - (id)initWithNamespace:(NSString *)ns {
  87 + NSString *path = [self makeDiskCachePath:ns];
  88 + return [self initWithNamespace:ns diskCacheDirectory:path];
  89 +}
  90 +
  91 +- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory {
87 if ((self = [super init])) { 92 if ((self = [super init])) {
88 NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns]; 93 NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
89 94
@@ -101,7 +106,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { @@ -101,7 +106,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
101 _memCache.name = fullNamespace; 106 _memCache.name = fullNamespace;
102 107
103 // Init the disk cache 108 // Init the disk cache
104 - _diskCachePath = [self makeDiskCachePath:fullNamespace]; 109 + if (directory != nil) {
  110 + _diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
  111 + } else {
  112 + NSString *path = [self makeDiskCachePath:ns];
  113 + _diskCachePath = path;
  114 + }
105 115
106 // Set decompression to YES 116 // Set decompression to YES
107 _shouldDecompressImages = YES; 117 _shouldDecompressImages = YES;