Up

# NSCache class documentation

### Authors

David Chisnall (`csdavec@swan.ac.uk`)

Date: Generated at 2025-02-13 06:02:40 +0000

Copyright: (C) 2009 Free Software Foundation, Inc.

### Contents -

1. Software documentation for the NSCache class
2. Software documentation for the NSCacheDelegate protocol

# Software documentation for the NSCache class

## NSCache : NSObject

> Declared in:
>   Foundation/NSCache.h

Availability: MacOS-X 10.6.0
Description forthcoming.
Method summary

- -countLimit
- -delegate
- -evictsObjectsWithDiscardedContent
- -name
- -objectForKey:
- -removeAllObjects
- -removeObjectForKey:
- -setCountLimit:
- -setDelegate:
- -setEvictsObjectsWithDiscardedContent:
- -setName:
- -setObject:forKey:
- -setObject:forKey:cost:
- -setTotalCostLimit:
- -totalCostLimit

### countLimit

- (NSUInteger) countLimit;
Availability: MacOS-X 10.6.0
Returns the maximum number of objects that are supported by this cache.

### delegate

- (id) delegate;
Availability: MacOS-X 10.6.0
Returns the cache's delegate.

### evictsObjectsWithDiscardedContent

- (BOOL) evictsObjectsWithDiscardedContent;
Availability: MacOS-X 10.6.0
Returns whether objects stored in this cache which implement the NSDiscardableContent protocol are removed from the cache when their contents are evicted.

### name

- (NSString*) name;
Availability: MacOS-X 10.6.0
Returns the name associated with this cache.

### objectForKey:

- (id) objectForKey: (id)key;
Availability: MacOS-X 10.6.0
Returns an object associated with the specified key in this cache.

### removeAllObjects

- (void) removeAllObjects;
Availability: MacOS-X 10.6.0
Removes all objects from this cache.

### removeObjectForKey:

- (void) removeObjectForKey: (id)key;
Availability: MacOS-X 10.6.0
Removes the object associated with the given key.

### setCountLimit:

- (void) setCountLimit: (NSUInteger)lim;
Availability: MacOS-X 10.6.0
Sets the maximum number of objects permitted in this cache. This limit is advisory; caches may choose to disregard it temporarily or permanently. A limit of 0 is used to indicate no limit; this is the default.

### setDelegate:

- (void) setDelegate: (id)del;
Availability: MacOS-X 10.6.0
Sets the delegate for this cache. The delegate will be notified when an object is being evicted or removed from the cache.

### setEvictsObjectsWithDiscardedContent:

- (void) setEvictsObjectsWithDiscardedContent: (BOOL)b;
Availability: MacOS-X 10.6.0
Sets whether this cache will evict objects that conform to the NSDiscardableContent protocol, or simply discard their contents.

### setName:

- (void) setName: (NSString*)cacheName;
Availability: MacOS-X 10.6.0
Sets the name for this cache.

### setObject: forKey:

- (void) setObject: (id)obj forKey: (id)key;
Availability: MacOS-X 10.6.0
Adds an object to the cache without associating a cost with it.

### setObject: forKey: cost:

- (void) setObject: (id)obj forKey: (id)key cost: (NSUInteger)num;
Availability: MacOS-X 10.6.0
Adds an object and its associated cost. The cache will endeavor to keep the total cost below the value set with -setTotalCostLimit: by discarding the contents of objects which implement the NSDiscardableContent protocol.

### setTotalCostLimit:

- (void) setTotalCostLimit: (NSUInteger)lim;
Availability: MacOS-X 10.6.0
Sets the maximum total cost for objects stored in this cache. This limit is advisory; caches may choose to disregard it temporarily or permanently. A limit of 0 is used to indicate no limit; this is the default.

### totalCostLimit

- (NSUInteger) totalCostLimit;
Availability: MacOS-X 10.6.0
Returns the total cost of all objects held in the cache.

# Software documentation for the NSCacheDelegate protocol

## NSCacheDelegate

> Declared in:
>   Foundation/NSCache.h

Availability: MacOS-X 10.6.0
Protocol implemented by NSCache delegate objects.
Method summary

- -cache:willEvictObject:

### cache: willEvictObject:

- (void) cache: (NSCache*)cache willEvictObject: (id)obj;
Availability: MacOS-X 10.6.0
Delegate method, called just before the cache removes an object, either as the result of user action or due to the cache becoming full.

Up