Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PINCache] Set a default .byteLimit to reduce disk usage & startup time. #595

Merged
merged 2 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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)
Expand Down
25 changes: 24 additions & 1 deletion 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 @@ -84,7 +93,21 @@ @implementation ASPINRemoteImageManager
//Share image cache with sharedImageManager image cache.
- (id <PINRemoteImageCaching>)defaultImageCache
{
return [[PINRemoteImageManager sharedImageManager] cache];
static dispatch_once_t onceToken;
static id <PINRemoteImageCaching> cache = nil;
dispatch_once(&onceToken, ^{
cache = [[PINRemoteImageManager sharedImageManager] cache];
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;
}

@end
Expand Down