Inherits from NSObject
Declared in RKEntityCache.h

Overview

Instances of RKInMemoryEntityCache provide an in-memory caching mechanism for objects in a Core Data managed object context. Managed objects can be cached by attribute for fast retrieval without repeatedly hitting the Core Data persistent store. This can provide a substantial speed advantage over issuing fetch requests in cases where repeated look-ups of the same data are performed using a small set of attributes as the query key. Internally, the cache entries are maintained as references to the NSManagedObjectID of corresponding cached objects.

Tasks

Initializing the Cache

Caching Objects by Attributes

Properties

managedObjectContext

The managed object context with which the receiver is associated.

@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext

Declared In

RKEntityCache.h

Instance Methods

addObject:

Adds a given object to all entity attribute caches for the object’s entity contained within the receiver.

- (void)addObject:(NSManagedObject *)object

Parameters

object

The object to add to the appropriate entity attribute caches.

Declared In

RKEntityCache.h

attributeCacheForEntity:attributes:

Retrieves the underlying entity attribute cache for a given entity and attribute.

- (RKEntityByAttributeCache *)attributeCacheForEntity:(NSEntityDescription *)entity attributes:(NSArray *)attributeNames

Parameters

entity

The entity to retrieve the entity attribute cache object for.

attributeName

The attribute to retrieve the entity attribute cache object for.

Return Value

The entity attribute cache for the given entity and attribute, or nil if none was found.

Declared In

RKEntityCache.h

attributeCachesForEntity:

Retrieves all entity attributes caches for a given entity.

- (NSArray *)attributeCachesForEntity:(NSEntityDescription *)entity

Parameters

entity

The entity to retrieve the collection of entity attribute caches for.

Return Value

An array of entity attribute cache objects for the given entity or an empty array if none were found.

Declared In

RKEntityCache.h

cacheObjectsForEntity:byAttributes:

Caches all instances of an entity using the value for an attribute as the cache key.

- (void)cacheObjectsForEntity:(NSEntityDescription *)entity byAttributes:(NSArray *)attributeNames

Parameters

entity

The entity to cache all instances of.

attributeNames

The attributes to cache the instances by.

Declared In

RKEntityCache.h

flush

Flushes the entity cache by sending a flush message to each entity attribute cache contained within the receiver.

- (void)flush

Declared In

RKEntityCache.h

initWithManagedObjectContext:

Initializes the receiver with a managed object context containing the entity instances to be cached.

- (id)initWithManagedObjectContext:(NSManagedObjectContext *)context

Parameters

context

The managed object context containing objects to be cached.

Return Value

self, initialized with context.

Declared In

RKEntityCache.h

isEntity:cachedByAttributes:

Returns a Boolean value indicating if all instances of an entity have been cached by a given attribute name.

- (BOOL)isEntity:(NSEntityDescription *)entity cachedByAttributes:(NSArray *)attributeNames

Parameters

entity

The entity to check the cache status of.

attributeNames

The attributes to check the cache status with.

Return Value

YES if the cache has been loaded with instances with the given attribute, else NO.

Declared In

RKEntityCache.h

objectForEntity:withAttributeValues:inContext:

Retrieves the first cached instance of a given entity where the specified attribute matches the given value.

- (NSManagedObject *)objectForEntity:(NSEntityDescription *)entity withAttributeValues:(NSDictionary *)attributeValues inContext:(NSManagedObjectContext *)context

Parameters

entity

The entity to search the cache for instances of.

attributeValues

The attribute values return a match for.

context

The managed object from which to retrieve the cached results.

Return Value

A matching managed object instance or nil. @raise NSInvalidArgumentException Raised if instances of the entity and attribute have not been cached.

Declared In

RKEntityCache.h

objectsForEntity:withAttributeValues:inContext:

Retrieves all cached instances of a given entity where the specified attribute matches the given value.

- (NSSet *)objectsForEntity:(NSEntityDescription *)entity withAttributeValues:(NSDictionary *)attributeValues inContext:(NSManagedObjectContext *)context

Parameters

entity

The entity to search the cache for instances of.

attributeValues

The attribute values return a match for.

context

The managed object from which to retrieve the cached results.

Return Value

All matching managed object instances or nil. @raise NSInvalidArgumentException Raised if instances of the entity and attribute have not been cached.

Declared In

RKEntityCache.h

removeObject:

Removed a given object from all entity attribute caches for the object’s entity contained within the receiver.

- (void)removeObject:(NSManagedObject *)object

Parameters

object

The object to remove from the appropriate entity attribute caches.

Declared In

RKEntityCache.h