/** * Returns the instance of this class associated with this user and community. * * @param account User account. * @param communityId Community ID. * @return Instance of this class. */ public static synchronized CacheManager getInstance(UserAccount account, String communityId) { if (account == null) { account = SmartStoreSDKManager.getInstance().getUserAccountManager().getCurrentUser(); } if (account == null) { return null; } String uniqueId = account.getUserId(); if (UserAccount.INTERNAL_COMMUNITY_ID.equals(communityId)) { communityId = null; } if (!TextUtils.isEmpty(communityId)) { uniqueId = uniqueId + communityId; } CacheManager instance = null; if (INSTANCES == null) { INSTANCES = new HashMap<String, CacheManager>(); instance = new CacheManager(account, communityId); INSTANCES.put(uniqueId, instance); } else { instance = INSTANCES.get(uniqueId); } if (instance == null) { instance = new CacheManager(account, communityId); INSTANCES.put(uniqueId, instance); } instance.resetInMemoryCache(); return instance; }
/** * Resets the cache manager for this user account. This method clears the in memory cache and the * underlying cache in the database. * * @param account User account. * @param communityId Community ID. */ public static synchronized void hardReset(UserAccount account, String communityId) { if (account == null) { account = SmartStoreSDKManager.getInstance().getUserAccountManager().getCurrentUser(); } if (account != null) { String uniqueId = account.getUserId(); if (UserAccount.INTERNAL_COMMUNITY_ID.equals(communityId)) { communityId = null; } if (!TextUtils.isEmpty(communityId)) { uniqueId = uniqueId + communityId; } if (getInstance(account, communityId) != null) { getInstance(account, communityId).cleanCache(); if (INSTANCES != null) { INSTANCES.remove(uniqueId); } } } }