Click here to support Nimbus development and make a donation at www.pledgie.com !
An iOS framework whose growth is bounded by O(documentation).
NIImageMemoryCache Class Reference

Overview

An in-memory cache for storing images with caps on the total number of pixels.

When reduceMemoryUsage is called, the least recently used images are removed from the cache until the numberOfPixels is below maxNumberOfPixelsUnderStress.

When an image is added to the cache that causes the memory usage to pass the max, the least recently used images are removed from the cache until the numberOfPixels is below maxNumberOfPixels.

By default the image memory cache has no limit to its pixel count. You must explicitly set this value in your application.

Attention:
If the cache is too small to fit the newly added image, then all images will end up being removed including the one being added.
See also:
+ imageMemoryCache (Nimbus)
+ setImageMemoryCache: (Nimbus)

Definition at line 89 of file NIInMemoryCache.h.

Inheritance diagram for NIImageMemoryCache:
NIMemoryCache

Methods

Querying an In-Memory Image Cache
NSUInteger numberOfPixels property
Setting the Maximum Number of Pixels
NSUInteger maxNumberOfPixels property
NSUInteger maxNumberOfPixelsUnderStress property
Creating an In-Memory Cache
(id) - initWithCapacity:
Querying an In-Memory Cache
(NSUInteger) - count
Storing Objects in the Cache
(void) - storeObject:withName:
(void) - storeObject:withName:expiresAfter:
Removing Objects from the Cache
(void) - removeObjectWithName:
(void) - removeAllObjects
Accessing Objects in the Cache
(id) - objectWithName:
(BOOL) - containsObjectWithName:
(NSDate *) - dateOfLastAccessWithName:
(NSString *) - nameOfLeastRecentlyUsedObject
(NSString *) - nameOfMostRecentlyUsedObject
Reducing Memory Usage Explicitly
(void) - reduceMemoryUsage
Subclassing

The following methods are provided to aid in subclassing and are not meant to be used externally.

(BOOL) - willSetObject:withName:previousObject:
(void) - didSetObject:withName:
(void) - willRemoveObject:withName:

Method Documentation

- NIImageMemoryCache: [read, assign]

Returns the total number of pixels being stored in the cache.

Returns:
The total number of pixels being stored in the cache.

Definition at line 90 of file NIInMemoryCache.h.

- NIImageMemoryCache: [read, write, assign]

The maximum number of pixels this cache may ever store.

Defaults to 0, which is special cased to represent an unlimited number of pixels.

Returns:
The maximum number of pixels this cache may ever store.

Definition at line 91 of file NIInMemoryCache.h.

- NIImageMemoryCache: [read, write, assign]

The maximum number of pixels this cache may store after a call to reduceMemoryUsage.

Defaults to 0, which is special cased to represent an unlimited number of pixels.

Returns:
The maximum number of pixels this cache may store after a call to reduceMemoryUsage.

Definition at line 92 of file NIInMemoryCache.h.

- (id) initWithCapacity: (NSUInteger)  capacity

Initializes a newly allocated cache with the given capacity.

Returns:
An in-memory cache initialized with the given capacity.

Definition at line 109 of file NIInMemoryCache.m.

- (NSUInteger) count

Returns the number of objects currently in the cache.

Returns:
The number of objects currently in the cache.

Definition at line 358 of file NIInMemoryCache.m.

- (void) storeObject: (id)  object
withName: (NSString *)  name 

Stores an object in the cache.

The object will be stored without an expiration date. The object will stay in the cache until it's bumped out due to the cache's memory limit.

Parameters:
objectThe object being stored in the cache.
nameThe name used as a key to store this object.

Definition at line 215 of file NIInMemoryCache.m.

- (void) storeObject: (id)  object
withName: (NSString *)  name
expiresAfter: (NSDate *)  expirationDate 

Stores an object in the cache with an expiration date.

If an object is stored with an expiration date that has already passed then the object will not be stored in the cache and any existing object will be removed. The rationale behind this is that the object would be removed from the cache the next time it was accessed anyway.

Parameters:
objectThe object being stored in the cache.
nameThe name used as a key to store this object.
expirationDateA date after which this object is no longer valid in the cache.

Definition at line 221 of file NIInMemoryCache.m.

- (void) removeObjectWithName: (NSString *)  name

Removes an object from the cache.

Parameters:
nameThe name used as a key to store this object.

Definition at line 328 of file NIInMemoryCache.m.

- (void) removeAllObjects

Removes all objects from the cache, regardless of expiration dates.

This will completely clear out the cache and all objects in the cache will be released.

Definition at line 334 of file NIInMemoryCache.m.

- (id) objectWithName: (NSString *)  name

Retrieves an object from the cache.

If the object has expired then the object will be removed from the cache and nil will be returned.

Returns:
The object stored in the cache. The object is retained and autoreleased to ensure that it survives this run loop if you then remove it from the cache.

Definition at line 254 of file NIInMemoryCache.m.

- (BOOL) containsObjectWithName: (NSString *)  name

Returns a Boolean value that indicates whether an object with the given name is present in the cache.

Does not update the access time of the object.

If the object has expired then the object will be removed from the cache and NO will be returned.

Returns:
YES if an object with the given name is present in the cache and has not expired, otherwise NO.

Definition at line 276 of file NIInMemoryCache.m.

- (NSDate *) dateOfLastAccessWithName: (NSString *)  name

Returns the date that the object with the given name was last accessed.

Does not update the access time of the object.

If the object has expired then the object will be removed from the cache and nil will be returned.

Returns:
The last access date of the object if it exists and has not expired, nil otherwise.

Definition at line 289 of file NIInMemoryCache.m.

- (NSString *) nameOfLeastRecentlyUsedObject

Retrieve the name of the object that was least recently used.

This will not update the access time of the object.

If the cache is empty, returns nil.

Definition at line 302 of file NIInMemoryCache.m.

- (NSString *) nameOfMostRecentlyUsedObject

Retrieve the key with the most fresh access.

This will not update the access time of the object.

If the cache is empty, returns nil.

Definition at line 315 of file NIInMemoryCache.m.

- (void) reduceMemoryUsage

Removes all expired objects from the cache.

Subclasses may add additional functionality to this implementation. Subclasses should call super in order to prune expired objects.

This will be called when UIApplicationDidReceiveMemoryWarningNotification is posted.

Definition at line 341 of file NIInMemoryCache.m.

- (BOOL) willSetObject: (id)  object
withName: (NSString *)  name
previousObject: (id)  previousObject 

An object is about to be stored in the cache.

Parameters:
objectThe object that is about to be stored in the cache.
nameThe cache name for the object.
previousObjectThe object previously stored in the cache. This may be the same as object.
Returns:
YES If object is allowed to be stored in the cache.

Definition at line 190 of file NIInMemoryCache.m.

- (void) didSetObject: (id)  object
withName: (NSString *)  name 

An object has been stored in the cache.

Parameters:
objectThe object that was stored in the cache.
nameThe cache name for the object.

Definition at line 197 of file NIInMemoryCache.m.

- (void) willRemoveObject: (id)  object
withName: (NSString *)  name 

An object is about to be removed from the cache.

Parameters:
objectThe object about to removed from the cache.
nameThe cache name for the object about to be removed.

Definition at line 203 of file NIInMemoryCache.m.

Generated for Nimbus by doxygen 1.7.4-20110629