The following ATGMobileCommon classes are used by the various Managers that need caching. For example, ATGProductManager uses ATGRepositoryCoreDataCache because it is caching products and SKUs that are repository items and ATGProfileManager uses ATGMemoryCache for its order caching.

Implementation

A singleton object of ATGMemoryCache is used so any object that needs to interact with the in-memory cache can, for example, pass ATGMemoryCache sharedInstance for access to the centralized cache.

This class broadcasts notifications for other objects, for example, if some view controllers might be interested in knowing when certain objects are removed from the cache so they can reset their state. This is implemented only for when the user’s profile is deleted, but this can be easily extended by customers to include other events. Below is the current implementation.

ATGMemoryCache.m
- (void) broadcastClearCacheNotifications:(NSString *)pID cache:(NSCache *) cache {
  // Broadcast a notification if we are about to delete the user's profile. If pID is nil this means we are clearing
  // everything in the cache, so broadcast a notification in this case too.
  if (pID == nil || [pID isEqualToString:ATG_USER_PROFILE_CACHE_ID ]) {
    ATGMemoryCacheItem *userProfile = [cache objectForKey:pID];
    if (userProfile) {
      [[NSNotificationCenter defaultCenter] postNotificationName:ATGMemoryCacheWillClearUserProfileNotification
                                                          object:nil];
    }
  }}

You can add other “if” statements to include the clear cache events they want to broadcast. Also, if they need to broadcast notifications for when items added to the cache they can just follow this clear cache example.


Copyright © 1997, 2016 Oracle and/or its affiliates. All rights reserved. Legal Notices