Skip to content

Commit

Permalink
[PINCache] Declare necessary APIs to avoid a direct dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
appleguy committed Sep 29, 2017
1 parent d7bff02 commit b63fc1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 & 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)
Expand Down
24 changes: 18 additions & 6 deletions Source/Details/ASPINRemoteImageDownloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -88,12 +97,15 @@ @implementation ASPINRemoteImageManager
static id <PINRemoteImageCaching> 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 <ASPINCache>)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 <ASPINDiskCache>)diskCache).byteLimit = 20 * 1024 * 1024;
}
}
});
return cache;
}
Expand Down

0 comments on commit b63fc1e

Please sign in to comment.