ERXEnterpriseObjectArrayCache< T extends EOEnterpriseObject > Class Reference

Collaboration diagram for ERXEnterpriseObjectArrayCache< T extends EOEnterpriseObject >:

Collaboration graph
[legend]

List of all members.

Classes

class  NotFoundArray

Public Member Functions

void clearCaches (NSNotification n)
void editingContextDidSaveChanges (NSNotification n)
 ERXEnterpriseObjectArrayCache (String entityName, long timeout)
 ERXEnterpriseObjectArrayCache (Class c)
 ERXEnterpriseObjectArrayCache (String entityName)
NSArray< T > objectsForKey (EOEditingContext ec, Object key)
synchronized void reset ()
void setObjectsForKey (NSArray<?extends EOEnterpriseObject > bugs, Object key)

Protected Member Functions

NSArray< EOGlobalID > cachedArrayForKey (Object key)
String entityName ()
long fetchTime ()
void handleUnsuccessfullQueryForKey (Object key)
boolean isNotFound (NSArray< EOGlobalID > gids)
void registerForNotifications ()
void setCachedArrayForKey (NSArray< EOGlobalID > gids, Object key)
long timeout ()

Static Protected Member Functions

static String entityNameForClass (Class c)

Static Protected Attributes

static final NSArray NOT_FOUND_MARKER = new NotFoundArray()

Private Member Functions

synchronized Map cache ()
boolean hadRelevantChanges (NSDictionary dict, String key)

Private Attributes

Map< Object, NSArray
< EOGlobalID > > 
_cache
String _entityName
long _fetchTime
long _timeout


Detailed Description

Caches objects of one entity by a given key. Listens to EOEditingContextDidSaveChanges notifications to track changes. Typically you'd fetch values by:
 ERXEnterpriseObjectArrayCache<HelpText> helpTextCache = new ERXEnterpriseObjectArrayCache<HelpText>("HelpText") {
    protected void handleUnsuccessfullQueryForKey(Object key) {
       NSArray helpTexts = ... fetch from somewhere
       setObjectsForKey(helpTexts, key);
   }
 };
 ...
 NSArray<HelpText> helpTexts = helpTextCache.objectsForKey(ec, "AllTexts");
 ...
 
You can supply a timeout after which the cache is to get cleared and all the objects refetched. Note that this implementation only caches the global IDs, not the actual data.
Author:
ak

Constructor & Destructor Documentation

ERXEnterpriseObjectArrayCache ( String  entityName  ) 

Creates the cache for the given entity name and the given keypath. No timeout value is used.

Parameters:
entityName 

ERXEnterpriseObjectArrayCache ( Class  c  ) 

Creates the cache for the given entity name and the given keypath. No timeout value is used.

ERXEnterpriseObjectArrayCache ( String  entityName,
long  timeout 
)

Creates the cache for the given entity, keypath and timeout value in milliseconds.

Parameters:
entityName 
timeout 


Member Function Documentation

synchronized Map cache (  )  [private]

Returns the backing cache. If the cache is to old, it is cleared first.

NSArray<EOGlobalID> cachedArrayForKey ( Object  key  )  [protected]

void clearCaches ( NSNotification  n  ) 

Handler for the clearCaches notification. Calls reset if n.object is the entity name.

Parameters:
n 

void editingContextDidSaveChanges ( NSNotification  n  ) 

Handler for the editingContextDidSaveChanges notification. Calls reset if and object of the given entity were changed.

Parameters:
n 

String entityName (  )  [protected]

static String entityNameForClass ( Class  c  )  [static, protected]

long fetchTime (  )  [protected]

boolean hadRelevantChanges ( NSDictionary  dict,
String  key 
) [private]

Helper to check if an array of EOs contains the handled entity.

Parameters:
eos 

void handleUnsuccessfullQueryForKey ( Object  key  )  [protected]

Called when a query hasn't found an entry in the cache. This implementation puts a not-found marker in the cache so the next query will return null. You could override this method to create an EO with sensible default values and call setObjectsForKey(NSArray, Object) on it.

Parameters:
key 

boolean isNotFound ( NSArray< EOGlobalID >  gids  )  [protected]

NSArray<T> objectsForKey ( EOEditingContext  ec,
Object  key 
)

Retrieves a list of EOs that matches the given key or null if no match is in the cache.

Parameters:
ec editing context to get the objects into
key key value under which the objects are registered

void registerForNotifications (  )  [protected]

synchronized void reset (  ) 

Resets the cache by clearing the internal map. When the next value is accessed, the objects are refetched.

void setCachedArrayForKey ( NSArray< EOGlobalID >  gids,
Object  key 
) [protected]

void setObjectsForKey ( NSArray<?extends EOEnterpriseObject >  bugs,
Object  key 
)

Add a list of objects to the cache with the given key. The object can be null.

Parameters:
bugs array of objects

long timeout (  )  [protected]


Member Data Documentation

Map<Object, NSArray<EOGlobalID> > _cache [private]

String _entityName [private]

long _fetchTime [private]

long _timeout [private]

final NSArray NOT_FOUND_MARKER = new NotFoundArray() [static, protected]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:08 2012 for Project Wonder by  doxygen 1.5.8