NSCache
That’s right: NSCache is basically just an NSMutableDictionary that automatically evicts objects in order to free up space in memory as needed. No need to respond to memory warnings or contrive a cache-clearing timer mechanism. The only other difference is that keys aren’t copied as they are in an NSMutableDictionary, which is actually to its advantage (no need for keys to conform to NSCopying).
NSCache works like NSMutableDictionary but removes objects automatically when memory runs low. This saves you from handling memory warnings or setting up timers to clear space. Keys do not get copied, unlike in NSMutableDictionary, so they need not conform to NSCopying.
The cost parameter in setObject:forKey:cost: lacks clear guidance and may hurt performance if used wrong; stick to 0 or the basic setObject:forKey:. Avoid evictsObjectsWithDiscardedContent to prevent issues. Replace your custom caches with NSCache, but use only core methods: objectForKey:, setObject:forKey:, and removeObjectForKey:.
Category:
Tags:
Year: