Article From:
 NSUInteger cost = SDCacheCostForImage(diskImage);
[self.memCache setObject:diskImage forKey:key cost:cost];
FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
#if SD_MAC
    return image.size.height * image.size.width;
    return image.size.height * image.size.width * image.scale * image.scale;

I looked at the document pair

- (void)setObject:(ObjectType)obj forKey:(KeyType)key cost:(NSUInteger)g

The explanation is that it is clear that cost should be a byte value, and if this information is not useful, you should not calculate it through troublesome steps, because such a calculation will increase the cost of using caching, 0 when this thing is useless to you, or directly with the setObject:forK.Ey: method. This does not require the transmission of cost.
My question is whether it is necessary for him to do this calculation and whether the calculation is correct.

Answer 0:

NSCacheThere’s a totalCostLimit, look at his description.
The simple conclusion is that if the totalCostLimit is set up when setting the global cache instance, the method call of the storage cache is bound to take the cost, otherwise totalCostLimit is useless.

Leave a Reply

Your email address will not be published. Required fields are marked *