Skip to content

Commit

Permalink
Added support for custom disk cache folder with fall back for caches …
Browse files Browse the repository at this point in the history
…directory
  • Loading branch information
LukeDurrant committed May 20, 2015
1 parent 91b4251 commit 737140d
Show file tree
Hide file tree
Showing 2 changed files with 22 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
15 changes: 14 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 {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
return [self initWithNamespace:ns diskCacheDirectory:paths[0]];
}

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

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

// Init the disk cache
_diskCachePath = [self makeDiskCachePath:fullNamespace];
if(directory!=nil)
{
_diskCachePath = [directory stringByAppendingPathComponent:fullNamespace];
}
else
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_diskCachePath = [paths[0] stringByAppendingString:fullNamespace];
}

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

0 comments on commit 737140d

Please sign in to comment.