From 596521ec97327859586705671936e3673b2327aa Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Fri, 29 Sep 2017 16:31:42 -0700 Subject: [PATCH] [PINCache] Declare necessary APIs to avoid a direct dependency. --- CHANGELOG.md | 1 + Source/Details/ASPINRemoteImageDownloader.m | 24 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd484096e..835422a94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## master * Add your own contributions to the next release on the line below this with your name. +- [PINCache] Set a default .byteLimit to reduce disk usage and startup time. [#595](https://github.com/TextureGroup/Texture/pull/595) [Scott Goodson](https://github.com/appleguy) - [ASNetworkImageNode] Fix deadlock in GIF handling. [#582](https://github.com/TextureGroup/Texture/pull/582) [Garrett Moon](https://github.com/garrettmoon) - [ASDisplayNode] Add attributed versions of a11y label, hint and value. [#554](https://github.com/TextureGroup/Texture/pull/554) [Alexander Hüllmandel](https://github.com/fruitcoder) - [ASCornerRounding] Introduce .cornerRoundingType: CALayer, Precomposited, or Clip Corners. [Scott Goodson](https://github.com/appleguy) [#465](https://github.com/TextureGroup/Texture/pull/465) diff --git a/Source/Details/ASPINRemoteImageDownloader.m b/Source/Details/ASPINRemoteImageDownloader.m index 2fe5d0509..601d00945 100644 --- a/Source/Details/ASPINRemoteImageDownloader.m +++ b/Source/Details/ASPINRemoteImageDownloader.m @@ -76,6 +76,15 @@ - (BOOL)isDataSupported:(NSData *)data @end #endif +// Declare two key methods on PINCache objects, avoiding a direct dependency on PINCache.h +@protocol ASPINCache +- (id)diskCache; +@end + +@protocol ASPINDiskCache +@property (assign) NSUInteger byteLimit; +@end + @interface ASPINRemoteImageManager : PINRemoteImageManager @end @@ -88,12 +97,15 @@ @implementation ASPINRemoteImageManager static id cache = nil; dispatch_once(&onceToken, ^{ cache = [[PINRemoteImageManager sharedImageManager] cache]; - - // Set a default byteLimit. PINCache recently implemented a 50MB default (PR #201). - // Ensure that older versions of PINCache also have a byteLimit applied. - PINDiskCache *diskCache = [ASDynamicCast(cache, PINCache) diskCache]; - // NOTE: Using 20MB limit while large cache initialization is being optimized (Issue #144). - diskCache.byteLimit = 20 * 1024 * 1024; + if ([cache respondsToSelector:@selector(diskCache)]) { + id diskCache = [(id )cache diskCache]; + if ([diskCache respondsToSelector:@selector(setByteLimit:)]) { + // Set a default byteLimit. PINCache recently implemented a 50MB default (PR #201). + // Ensure that older versions of PINCache also have a byteLimit applied. + // NOTE: Using 20MB limit while large cache initialization is being optimized (Issue #144). + ((id )diskCache).byteLimit = 20 * 1024 * 1024; + } + } }); return cache; }