diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 5d2a48c..fabbe59 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -147,6 +147,12 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO /// Clears the persistent JSON cache - (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 /// Register a bundle as one to search for images in. diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 4f90380..60ad720 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -181,6 +181,14 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; 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 - (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]; if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) { - [[PersistentCacheManager shared] removeForKey:pageType error:nil]; + [self removePersistentJSONCacheForPageType:pageType pageJSON:jsonDictionary]; return; } [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]; if (![self shouldPersistentlyCacheModule:jsonDictionary module:module]) { - [[PersistentCacheManager shared] removeForKey:module error:nil]; + [self removePersistentModuleCacheForModule:module moduleJSON:jsonDictionary]; return; } [self addModuleToPersistentCache:jsonDictionary moduleName:module expirationDate:[self getExpirationDateForJSON:jsonDictionary]];