diff --git a/SDWebImage/SDImageCache.h b/SDWebImage/SDImageCache.h index 4a571c1c..7a76ca19 100644 --- a/SDWebImage/SDImageCache.h +++ b/SDWebImage/SDImageCache.h @@ -32,6 +32,11 @@ typedef enum SDImageCacheType SDImageCacheType; */ @interface SDImageCache : NSObject +/** + * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. + */ +@property (assign, nonatomic) NSUInteger maxMemoryCost; + /** * 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 e55ec71a..8ffed7b1 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -338,6 +338,16 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week } } +- (void)setMaxMemoryCost:(NSUInteger)maxMemoryCost +{ + self.memCache.totalCostLimit = maxMemoryCost; +} + +- (NSUInteger)maxMemoryCost +{ + return self.memCache.totalCostLimit; +} + - (void)clearMemory { [self.memCache removeAllObjects];