Skip to content
Closed
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
3 changes: 3 additions & 0 deletions Libraries/Image/RCTImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@
@end

@interface RCTImageCache : NSObject <RCTImageCache>

RCT_EXTERN void RCTSetImageCacheLimits(NSUInteger maxCachableDecodedImageSizeInBytes, NSUInteger imageCacheTotalCostLimit);

@end
10 changes: 8 additions & 2 deletions Libraries/Image/RCTImageCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

#import <React/RCTImageUtils.h>

static const NSUInteger RCTMaxCachableDecodedImageSizeInBytes = 2097152; // 2 MB
static NSUInteger RCTMaxCachableDecodedImageSizeInBytes = 2*1024*1024;
static NSUInteger RCTImageCacheTotalCostLimit = 20*1024*1024;

void RCTSetImageCacheLimits(NSUInteger maxCachableDecodedImageSizeInBytes, NSUInteger imageCacheTotalCostLimit) {
RCTMaxCachableDecodedImageSizeInBytes = maxCachableDecodedImageSizeInBytes;
RCTImageCacheTotalCostLimit = imageCacheTotalCostLimit;
}

static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat scale,
RCTResizeMode resizeMode)
Expand All @@ -38,7 +44,7 @@ - (instancetype)init
{
if (self = [super init]) {
_decodedImageCache = [NSCache new];
_decodedImageCache.totalCostLimit = 20 * 1024 * 1024; // 20 MB
_decodedImageCache.totalCostLimit = RCTImageCacheTotalCostLimit;
_cacheStaleTimes = [NSMutableDictionary new];

[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down