change image cache method

This commit is contained in:
Pan, Xinlei (Ryan) 2018-03-15 13:48:41 -04:00
parent 56f53e061f
commit 2217fe0770

View File

@ -528,7 +528,19 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
// Gets the full path
NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip];
if (s7URL) {
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:200*1024*1024 diskCapacity:200*1024*1024 diskPath:nil];
NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration];
configure.URLCache = sharedCache;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configure];
NSURLRequest *request = [NSURLRequest requestWithURL:s7URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1800];
NSURLSessionDownloadTask *downloadImageTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"HEADDERRRSS %i for %@ %@", ((NSHTTPURLResponse *)response).statusCode,s7URL.absoluteString,((NSHTTPURLResponse *)response).allHeaderFields.description);
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:location] scale:[UIScreen mainScreen].scale];
completionHandler(image, nil, isFallBackImage);
}];
[downloadImageTask resume];
return;
/*
// Check in memory cache
img = [self getCachedImageWithName:s7URL.absoluteString];
@ -538,7 +550,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
if (img) {
[self addImageToCache:img withName:s7URL.absoluteString];
}
}
}*/
}
} else {