Tuesday, May 7, 2013

NSCache totalCostLimit example ios


totalCostLimit

Returns the maximum total cost that the cache can have before it starts evicting objects.
- (NSUInteger)totalCostLimit
Return Value
The current maximum cost that the cache can have before it starts evicting objects.
Discussion of [NSCache totalCostLimit]
The default value is 0, which means there is no limit on the size of the cache. If you add an object to the cache, you may pass in a specified cost for the object, such as the size in bytes of the object. If adding this object to the cache causes the cache’s total cost to rise above totalCostLimit, the cache could automatically evict some of its objects until its total cost falls below totalCostLimit. The order in which the cache evicts objects is not guaranteed. This limit is not a strict limit, and if the cache goes over the limit, an object in the cache could be evicted instantly, at a later point in time, or possibly never, all depending on the implementation details of the cache.
Example of [NSCache totalCostLimit]
cache = [[NSCache alloc] init];
[cache setCountLimit:100];
[cache setTotalCostLimit:1500000];
[cache setEvictsObjectsWithDiscardedContent:YES];