SDMCache class

Deprecated. In-memory cache, providing additional features like data filtering and serialization.

Syntax

@interface SDMCache : NSObject <SDMCaching> <NSCoding>

Members

All members of SDMCache, including inherited members.

Methods
Method Description
+ (id) cacheWithServiceDoc: (SDMODataServiceDocument *) serviceDoc_in Static Factory method.
- (void) clear Should wipe out all cached content.
- (NSArray *) filterEntriesOfCollection: (NSString *) collectionName_in forSearchText: (NSString *) searchText_in Filters cached entries with searchable properties according to the search term.
- (NSArray *) getAllWorkspaces Retrieves all workspaces belonging to the stored SDMODataServiceDocument.
- (const SDMODataCollection *) getCollectionByName: (NSString *) collectionName_in Retrieves a collection based on it's name.
- (NSArray *) getCollectionsByWorkspace: (SDMODataWorkspace *) workspace_in Retrieves all collections for a given workspace.
- (NSMutableArray *) getODataEntriesByCollection: (NSString *) collectionName_in Retrieves an array of SDMODataEntry instance pointers.
- (const SDMODataEntry *) getODataEntryByCollection: (NSString *) collectionName_in andEntryId: (NSString *) entryId_in Retrieves the SDMODataServiceDocument.
- (NSArray *) getWorkspacesBySemantic: (enum TEN_WORKSPACE_SEMANTICS) semantic_in Retrieves the workspace based on the provided semantics.
- (id) initWithServiceDocument: (SDMODataServiceDocument *) serviceDoc_in Inits the SDMCache instance.
- (BOOL) removeODataEntriesForCollection: (NSString *) collectionName_in Removes all SDMODataEntry entries from the cache which belong to the given collection.
- (BOOL) removeODataEntry: (const SDMODataEntry *) entry_in forCollection: (NSString *) collectionName_in Removes an SDMODataEntry from the cache.
- (BOOL) removeODataServiceDocument Removes the cached SDMODataServiceDocument which acts as a root of the metadata tree.
- (void) setODataEntries: (NSArray *) entries_in byCollection: (NSString *) collectionName_in Stores an array of SDMODataEntry instance pointers.
- (void) setODataEntry: (const SDMODataEntry *) entry_in byCollection: (NSString *) collectionName_in Sets a valid metadata tree with a SDMODataServiceDocument as root, which will be kept in memory.
+ (void) setShouldAutoSaveOnMemoryWarning: (BOOL) flag_in Sets that the cache will be saved automatically if the application receives memory warning.
+ (BOOL) shouldAutoSaveOnMemoryWarning Get that the cache will be saved automatically if the application receives memory warning.
Inherited members from SDMCaching
Member Description
- (SDMODataServiceDocument *) getODataServiceDocument Should retrieve the SDMODataServiceDocument.
- (NSString *) getUid Returns with the unique id of the cache.
- (void) setODataServiceDocument: (SDMODataServiceDocument *) serviceDocument_in Should set a valid metadata tree with a SDMODataServiceDocument as root, which will be kept in memory.
- (void) setRegexSearchEnabled: (BOOL) flag_in Enables in-cache filtering using regular expressions.

Usage

Usage

// 1. Initalize Cache

SDMCache* cache = [SDMCache cacheWithServiceDoc:SvcDoc];
//the cache's UID is generated during the cache's initialization

//set the cache that it will be persisted automatically if the application receives a memory warning from the system
[SDMCache setShouldAutoSaveOnMemoryWarning:YES];
//the default value is NO, because if the user does not care about storing the uid and the library persists the cache, the user can not load the cache in without the uid

//get the UID from the cache
NSString* uid = [cache retrieveUID];

//store uid in UserDefaults to make it loadable in case of autoSaveOnMemoryWarning
[[NSUserDefaults standardUserDefaults] setObject:uid forKey: UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE ];
[[NSUserDefaults standardUserDefaults] synchronize];

// 2. Store Cache

//get UID from cache object
NSString* uid = [cache retrieveUID];
//store cache's uid in the UserDefaults for the UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE
[[NSUserDefaults standardUserDefaults] setObject:uid forKey: UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE ];
[[NSUserDefaults standardUserDefaults] synchronize];
//store cache
[[SDMPersistence instance] storeCache: cache];

//other (equivalent) solution
//store the cache and get the uid of the cache
NSString* uid = [[SDMPersistence instance] storeCache: cache];
//store cache's uid in the UserDefaults for the UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE
[[NSUserDefaults standardUserDefaults] setObject:uid forKey: UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE ];
[[NSUserDefaults standardUserDefaults] synchronize];

// 3. Load Cache

//load the previously persisted serviceDoc
NSString* uid = (NSString*)[[NSUserDefaults standardUserDefaults] objectForKey: UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE ];

#ifdef DEBUG
NSLog("Cache's Uid: %", uid);
#endif                  
if ([NSString isNullOrEmpty: uid]) {
       //There is no UID saved for the UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE
}else{
       //There is a UID saved for the UNIQUE_KEY_TO_STORE_AND_LOAD_THE_UID_OF_THE_CACHE

       //load the previosly persisted cache
       cache = [[SDMPersistence instance] loadCache:uid];