Inherits from NSObject
Declared in RKEntityCache.h

Overview

Instances of RKEntityCache 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

Configuring the Callback Queue

  •   callbackQueue

    The queue on which to dispatch callbacks for asynchronous operations. When nil, the main queue is used.

    property

Caching Objects by Attributes

Properties

callbackQueue

The queue on which to dispatch callbacks for asynchronous operations. When nil, the main queue is used.

@property (nonatomic, assign) dispatch_queue_t callbackQueue

Discussion

Default: nil

Declared In

RKEntityCache.h

managedObjectContext

The managed object context with which the receiver is associated.

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

Declared In

RKEntityCache.h

Instance Methods

addObjects:completion:

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

- (void)addObjects:(NSSet *)objects completion:(void ( ^ ) ( void ))completion

Parameters

objects

The set of objects to add to the appropriate entity attribute caches.

completion

An optional block to be executed when the object addition has completed.

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:completion:

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

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

Parameters

entity

The entity to cache all instances of.

attributeNames

The attributes to cache the instances by.

Declared In

RKEntityCache.h

containsObject:

Returns a Boolean value that indicates if the receiver contains the given object in any of its attribute caches.

- (BOOL)containsObject:(NSManagedObject *)managedObject

Parameters

managedObject

The object to check for.

Return Value

YES if the receiver contains the given object in one or more of its caches, else NO.

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:(void ( ^ ) ( void ))completion

Parameters

completion

An optional block to be executed when the flush has completed.

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

The receiver, initialized with the given 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

removeObjects:completion:

Removes the given set of objects from all entity attribute caches for the object’s entity contained within the receiver.

- (void)removeObjects:(NSSet *)objects completion:(void ( ^ ) ( void ))completion

Parameters

objects

The set of objects to remove from the appropriate entity attribute caches.

completion

An optional block to be executed when the object removal has completed.

Declared In

RKEntityCache.h