From a1c6332131d391adddb3903b2c27f31944655bb1 Mon Sep 17 00:00:00 2001 From: Xi Zhang Date: Mon, 17 Jun 2024 20:39:39 -0400 Subject: [PATCH 1/2] Add support for removing persistent cache properly. --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 6 ++++++ MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 5d2a48c..e4680b0 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 pageType. +- (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]]; From 25e05c6c531327672c42d144579c8a5fdb3aa8cf Mon Sep 17 00:00:00 2001 From: Xi Zhang Date: Mon, 17 Jun 2024 20:55:20 -0400 Subject: [PATCH 2/2] update API description. --- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index e4680b0..fabbe59 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -150,7 +150,7 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO // 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 pageType. +// Removes a json dictionary from the cache by moduleType. - (void)removePersistentModuleCacheForModule:(nonnull NSString *)moduleType moduleJSON:(nonnull NSDictionary *)jsonDictionary; #pragma mark Image Functions