allow override diskCachePath

This commit is contained in:
Evgeny Petrov 2015-02-16 15:56:30 +03:00
parent feca1e8d0d
commit 6468a92f32
2 changed files with 9 additions and 2 deletions

View File

@ -65,6 +65,8 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot
*/ */
- (id)initWithNamespace:(NSString *)ns; - (id)initWithNamespace:(NSString *)ns;
-(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
/** /**
* Add a read-only cache path to search for images pre-cached by SDImageCache * 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 * Useful if you want to bundle pre-loaded images with your app

View File

@ -74,8 +74,7 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
_memCache.name = fullNamespace; _memCache.name = fullNamespace;
// Init the disk cache // Init the disk cache
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); _diskCachePath = [self makeDiskCachePath:fullNamespace];
_diskCachePath = [paths[0] stringByAppendingPathComponent:fullNamespace];
dispatch_sync(_ioQueue, ^{ dispatch_sync(_ioQueue, ^{
_fileManager = [NSFileManager new]; _fileManager = [NSFileManager new];
@ -144,6 +143,12 @@ BOOL ImageDataHasPNGPreffix(NSData *data) {
#pragma mark ImageCache #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 { - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk {
if (!image || !key) { if (!image || !key) {
return; return;