Tuesday, May 7, 2013

NSCache setCountLimit example ios


setCountLimit:

Sets the maximum number of objects that the cache can hold.
- (void)setCountLimit:(NSUInteger)lim
Parameters
lim
The maximum number of objects that the cache will be allowed to hold.
Discussion of [NSCache setCountLimit]
Setting the count limit to a number less than or equal to 0 will have no effect on the maximum size of the cache.

Example of [NSCache setCountLimit]
cache = [[NSCache alloc] init];
[cache setCountLimit:100];
[cache setTotalCostLimit:1500000];
[cache setEvictsObjectsWithDiscardedContent:YES];

Example of [NSCache setCountLimit]
+(NSCache*)sharedCache;
{
    static NSCache* sharedCache = nil;
    if (sharedCache == nil) {
        sharedCache = [[[self alloc] init] retain];
        [sharedCache setCountLimit:100];
    }
    return sharedCache;
}