From 6edf0ab99c5c61bee810ddaca6cd83ed26978621 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 10 May 2018 12:50:46 -0400 Subject: [PATCH] variable name change. cache tied from session --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 37 ++++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 68f2f00..da02bb1 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -488,7 +488,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; - (void)getImage:(nonnull NSString *)pathOrName useWidth:(BOOL)useWidth widthForS7:(NSInteger)widthForS7 useHeight:(BOOL)useHeight heightForS7:(NSInteger)heightForS7 format:(nullable NSString *)format finalRect:(CGRect)finalRect flipImage:(BOOL)flip localFallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - UIImage *img = nil; + UIImage *image = nil; if (pathOrName.length > 0) { // try the url if it's a url. if (pathOrName.length >=4 && [[pathOrName substringToIndex:4] isEqualToString:@"http"]) { @@ -500,27 +500,27 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } } else { // Try native image. Check in memory cache - img = [self getCachedImageWithName:pathOrName]; - if (!img) { - img = [UIImage imageNamed:pathOrName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; - - if (img) { - [self addImageToCache:img withName:pathOrName]; + image = [self getCachedImageWithName:pathOrName]; + if (!image) { + image = [UIImage imageNamed:pathOrName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; + if (image) { + [self addImageToCache:image withName:pathOrName]; } } } } - [self checkImage:img imageData:nil fallbackImage:fallbackImageName completionHandler:completionHandler]; + [self checkImage:image imageData:nil fallbackImage:fallbackImageName completionHandler:completionHandler]; }); } //download image - (void)downloadImage:(NSURL *)s7URL isGif:(BOOL)isGif fallbackImageName:(nullable NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { - NSURLCache *sharedCache = [NSURLCache sharedURLCache]; NSURLSession *session = [MVMCoreSessionObject sharedGlobal].session; + NSURLCache *sharedCache = session.configuration.URLCache; NSURLRequest *request = [NSURLRequest requestWithURL:s7URL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:ImageTimeOut]; - //use Freebee to download image first, then store image to cache + + //use Freebee to download image first if it is not already in the cache, then store image to cache NSCachedURLResponse *cachedResponse = [sharedCache cachedResponseForRequest:request]; if (!cachedResponse.data) { cachedResponse = [[MFFreebeeHandler sharedHandler] freebee_dataWithContentsOfURL:s7URL]; @@ -541,7 +541,6 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; [self checkImage:nil imageData:data fallbackImage:fallbackImageName completionHandler:completionHandler]; } else { UIImage *image = [UIImage imageWithData:data scale:[UIScreen mainScreen].scale]; - //check fallback image [self checkImage:image imageData:nil fallbackImage:fallbackImageName completionHandler:completionHandler]; } }]; @@ -549,24 +548,24 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } //check whether get image or imageData, if not, return fallbackImage -- (void)checkImage:(UIImage *)img imageData:(NSData *)imageData fallbackImage:(NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler{ +- (void)checkImage:(UIImage *)image imageData:(NSData *)imageData fallbackImage:(NSString *)fallbackImageName completionHandler:(nonnull MVMCoreGetImageBlock)completionHandler { // Set to the fallback image. BOOL isFallBackImage = NO; - if (!img && !imageData && fallbackImageName) { + if (!image && !imageData && fallbackImageName) { isFallBackImage = YES; // Grab fallback from cache - img = [self getCachedImageWithName:fallbackImageName]; - if (!img) { + image = [self getCachedImageWithName:fallbackImageName]; + if (!image) { - img = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; - if (img) { + image = [UIImage imageNamed:fallbackImageName inBundle:[self bundleToUseForImages] compatibleWithTraitCollection:nil]; + if (image) { // Cache the fallback image if not already cached. - [self addImageToCache:img withName:fallbackImageName]; + [self addImageToCache:image withName:fallbackImageName]; } } } - completionHandler(img, imageData, isFallBackImage); + completionHandler(image, imageData, isFallBackImage); } - (nullable UIImage *)getCachedImageWithName:(nonnull NSString *)imageName {