Skip to content

Commit

Permalink
Merge pull request SDWebImage#1153 from LukeDurrant/CustomDiskCachePath
Browse files Browse the repository at this point in the history
Custom disk cache path
  • Loading branch information
bpoplauschi committed Jul 13, 2015
2 parents f611d5e + 33c13e7 commit ba335fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions SDWebImage/SDImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
*/
- (id)initWithNamespace:(NSString *)ns;

/**
* Init a new cache store with a specific namespace and directory
*
* @param ns The namespace to use for this cache store
* @param directory Directory to cache disk images in
*/
- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;

-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;

/**
Expand Down
12 changes: 11 additions & 1 deletion SDWebImage/SDImageCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ - (id)init {
}

- (id)initWithNamespace:(NSString *)ns {
NSString *path = [self makeDiskCachePath:ns];
return [self initWithNamespace:ns diskCacheDirectory:path];
}

- (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory {
if ((self = [super init])) {
NSString *fullNamespace = [@"com.hackemist.SDWebImageCache." stringByAppendingString:ns];

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

// Init the disk cache
_diskCachePath = [self makeDiskCachePath:fullNamespace];
if (directory != nil) {
_diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
} else {
NSString *path = [self makeDiskCachePath:ns];
_diskCachePath = path;
}

// Set decompression to YES
_shouldDecompressImages = YES;
Expand Down

0 comments on commit ba335fc

Please sign in to comment.