Merge branch 'feature/offlineFeedbackClearAppCache' into 'release/20_0_0'

Add support for removing persistent cache properly.

Add support for removing persistent cache properly including the application level cache.

JIRA:
MVAPCT-155

Co-authored-by: Xi Zhang <xi.zhang@verizon.com>

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core/-/merge_requests/335
This commit is contained in:
Pfeil, Scott Robert 2024-06-18 21:15:55 +00:00
commit 4bf30550ef
2 changed files with 16 additions and 2 deletions

View File

@ -147,6 +147,12 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO
/// Clears the persistent JSON cache /// Clears the persistent JSON cache
- (void)clearPersistentJSONCache; - (void)clearPersistentJSONCache;
// Removes a json dictionary from the cache by pageType.
- (void)removePersistentJSONCacheForPageType:(nonnull NSString *)pageType pageJSON:(nonnull NSDictionary *)jsonDictionary;
// Removes a json dictionary from the cache by moduleType.
- (void)removePersistentModuleCacheForModule:(nonnull NSString *)moduleType moduleJSON:(nonnull NSDictionary *)jsonDictionary;
#pragma mark Image Functions #pragma mark Image Functions
/// Register a bundle as one to search for images in. /// Register a bundle as one to search for images in.

View File

@ -181,6 +181,14 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
return [[PersistentCacheManager shared] loadForKey:moduleName path:[self getPathForPersistentCacheModule:moduleName] error:&error]; return [[PersistentCacheManager shared] loadForKey:moduleName path:[self getPathForPersistentCacheModule:moduleName] error:&error];
} }
- (void)removePersistentJSONCacheForPageType:(nonnull NSString *)pageType pageJSON:(nonnull NSDictionary *)jsonDictionary {
[[PersistentCacheManager shared] removeForKey:pageType error:nil];
}
- (void)removePersistentModuleCacheForModule:(nonnull NSString *)moduleType moduleJSON:(nonnull NSDictionary *)jsonDictionary {
[[PersistentCacheManager shared] removeForKey:moduleType error:nil];
}
#pragma mark - Advanced Fetch #pragma mark - Advanced Fetch
- (void)fetchJSONForPageType:(nullable NSString *)pageType queue:(nullable NSOperationQueue *)queue waitUntilFinished:(BOOL)waitUntilFinished completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler { - (void)fetchJSONForPageType:(nullable NSString *)pageType queue:(nullable NSOperationQueue *)queue waitUntilFinished:(BOOL)waitUntilFinished completionHandler:(nonnull void (^)(NSDictionary * _Nullable jsonDictionary))completionHandler {
@ -315,7 +323,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
[weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType]; [weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType];
if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) { if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) {
[[PersistentCacheManager shared] removeForKey:pageType error:nil]; [self removePersistentJSONCacheForPageType:pageType pageJSON:jsonDictionary];
return; return;
} }
[self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary]]; [self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary]];
@ -351,7 +359,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
[weakSelf.moduleCache setObject:jsonDictionary forKey:module]; [weakSelf.moduleCache setObject:jsonDictionary forKey:module];
if (![self shouldPersistentlyCacheModule:jsonDictionary module:module]) { if (![self shouldPersistentlyCacheModule:jsonDictionary module:module]) {
[[PersistentCacheManager shared] removeForKey:module error:nil]; [self removePersistentModuleCacheForModule:module moduleJSON:jsonDictionary];
return; return;
} }
[self addModuleToPersistentCache:jsonDictionary moduleName:module expirationDate:[self getExpirationDateForJSON:jsonDictionary]]; [self addModuleToPersistentCache:jsonDictionary moduleName:module expirationDate:[self getExpirationDateForJSON:jsonDictionary]];