Skip to content

Commit ba335fc

Browse files
committed
Merge pull request SDWebImage#1153 from LukeDurrant/CustomDiskCachePath
Custom disk cache path
2 parents f611d5e + 33c13e7 commit ba335fc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

SDWebImage/SDImageCache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
7676
*/
7777
- (id)initWithNamespace:(NSString *)ns;
7878

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+
7987
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
8088

8189
/**

SDWebImage/SDImageCache.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ - (id)init {
8484
}
8585

8686
- (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 {
8792
if ((self = [super init])) {
8893
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];
8994

@@ -101,7 +106,12 @@ - (id)initWithNamespace:(NSString *)ns {
101106
_memCache.name = fullNamespace;
102107

103108
// 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+
}
105115

106116
// Set decompression to YES
107117
_shouldDecompressImages = YES;

0 commit comments

Comments
 (0)