update url cache method
This commit is contained in:
parent
e4e617581c
commit
80d379609f
@ -528,18 +528,29 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
// Gets the full path
|
// Gets the full path
|
||||||
NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip];
|
NSURL *s7URL = [self handleS7Path:pathOrName useWidth:useWidth widthForS7:widthForS7 useHeight:useHeight heightForS7:heightForS7 format:format finalRect:finalRect flipImage:flip];
|
||||||
if (s7URL) {
|
if (s7URL) {
|
||||||
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:200*1024*1024 diskCapacity:200*1024*1024 diskPath:nil];
|
NSURLCache *sharedCache = [NSURLCache sharedURLCache];
|
||||||
|
[sharedCache setMemoryCapacity:200*1024*1024];
|
||||||
NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration];
|
NSURLSessionConfiguration *configure = [NSURLSessionConfiguration defaultSessionConfiguration];
|
||||||
configure.URLCache = sharedCache;
|
configure.URLCache = sharedCache;
|
||||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:configure];
|
NSURLSession *session = [NSURLSession sessionWithConfiguration:configure];
|
||||||
NSURLRequest *request = [NSURLRequest requestWithURL:s7URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1800];
|
NSURLRequest *request = [NSURLRequest requestWithURL:s7URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1800];
|
||||||
NSURLSessionDownloadTask *downloadImageTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
NSCachedURLResponse *response = [sharedCache cachedResponseForRequest:request];
|
||||||
NSLog(@"HEADDERRRSS %i for %@ %@", ((NSHTTPURLResponse *)response).statusCode,s7URL.absoluteString,((NSHTTPURLResponse *)response).allHeaderFields.description);
|
if (response != nil) {
|
||||||
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:location] scale:[UIScreen mainScreen].scale];
|
UIImage *image = [UIImage imageWithData:response.data scale:[UIScreen mainScreen].scale];
|
||||||
completionHandler(image, nil, isFallBackImage);
|
completionHandler(image, nil, isFallBackImage);
|
||||||
}];
|
return;
|
||||||
[downloadImageTask resume];
|
} else {
|
||||||
return;
|
NSURLSessionDownloadTask *downloadImageTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||||
|
NSData *data = [NSData dataWithContentsOfURL:location];
|
||||||
|
NSCachedURLResponse *cachedreponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data];
|
||||||
|
[sharedCache storeCachedResponse:cachedreponse forRequest:request];
|
||||||
|
NSLog(@"HEADDERRRSS %i for %@ %@", ((NSHTTPURLResponse *)response).statusCode,s7URL.absoluteString,((NSHTTPURLResponse *)response).allHeaderFields.description);
|
||||||
|
UIImage *image = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale];
|
||||||
|
completionHandler(image, nil, isFallBackImage);
|
||||||
|
}];
|
||||||
|
[downloadImageTask resume];
|
||||||
|
return;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
// Check in memory cache
|
// Check in memory cache
|
||||||
img = [self getCachedImageWithName:s7URL.absoluteString];
|
img = [self getCachedImageWithName:s7URL.absoluteString];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user