From f72f4c183d5ce0d7c4a558c1f09ae9ed81f782f9 Mon Sep 17 00:00:00 2001 From: Ryan Romanchuk Date: Mon, 11 May 2015 11:02:33 -0700 Subject: [PATCH] Add NSCache countLimit property in attempts to get better control of cache eviction. --- SDWebImage/SDImageCache.h | 5 +++++ SDWebImage/SDImageCache.m | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index f97799dc..0dd05d10 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -47,6 +47,11 @@ typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger tot */ @property (assign, nonatomic) NSUInteger maxMemoryCost; +/** + * The maximum number of objects the cache should hold. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCountLimit; + /** * The maximum length of time to keep an image in the cache, in seconds */ diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index c648c632..19357b6c 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -377,6 +377,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { return self.memCache.totalCostLimit; } +- (NSUInteger)maxMemoryCountLimit { + return self.memCache.countLimit; +} + +- (void)setMaxMemoryCountLimit:(NSUInteger)maxCountLimit { + self.memCache.countLimit = maxCountLimit; +} + - (void)clearMemory { [self.memCache removeAllObjects]; }