ERXEnterpriseObjectArrayCache< T extends EOEnterpriseObject > Class Reference
List of all members.
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:
-
| 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:
-
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:
-
| void editingContextDidSaveChanges |
( |
NSNotification |
n |
) |
|
Handler for the editingContextDidSaveChanges notification. Calls reset if and object of the given entity were changed.
- Parameters:
-
| 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:
-
| 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:
-
| 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:
-
| long timeout |
( |
|
) |
[protected] |
Member Data Documentation
Map<Object, NSArray<EOGlobalID> > _cache [private] |
The documentation for this class was generated from the following file: