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

Deprecations Methods

Properties

callbackQueue

@property (nonatomic, assign) dispatch_queue_t callbackQueue
Discussion

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

Default: nil

Declared In

RKEntityCache.h

managedObjectContext

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

The managed object context with which the receiver is associated.

Declared In

RKEntityCache.h

Instance Methods

addObject:

- (void)addObject:(NSManagedObject *)object

addObjects:completion:

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

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

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:

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

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

Parameters

entity

The entity to retrieve the entity attribute cache object for.

attributeNames

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:

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

Retrieves all entity attributes caches for a given 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:

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

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

Parameters

entity

The entity to cache all instances of.

attributeNames

The attributes to cache the instances by.

Declared In

RKEntityCache.h

containsObject:

- (BOOL)containsObject:(NSManagedObject *)managedObject
Discussion

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

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:

- (void)flush:(void ( ^ ) ( void ))completion
Discussion

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

Parameters

completion

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

Declared In

RKEntityCache.h

initWithManagedObjectContext:

- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)context
Discussion

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

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:

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

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

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:

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

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

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:

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

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

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:

- (void)removeObject:(NSManagedObject *)object

removeObjects:completion:

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

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

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