From 2217fe07702bcfc0f0438baa118f4bc031ea403b Mon Sep 17 00:00:00 2001 From: "Pan, Xinlei (Ryan)" Date: Thu, 15 Mar 2018 13:48:41 -0400 Subject: [PATCH] change image cache method --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index e0c5884..43c28c1 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -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 {