diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift index 16c4a8f..13df18d 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift @@ -134,3 +134,19 @@ extension PersistentCacheManager { } } +@objc public extension MVMCoreCache { + + @objc func shouldSaveAtAppLevel(infoDictionary:[String: AnyHashable]) -> Bool { + + guard let cachePolicy = infoDictionary[KeyCachePolicy] as? Dictionary, + let appLevelKey = cachePolicy[KeyAppVelelCachePolicy] as? Bool, + appLevelKey == true, + self.shouldCachePageJSON(infoDictionary, pageType: PageTypeOfflineFeedback) == true, + self.isJSONExpired(infoDictionary) == false else {return false} + return true + } +} + + + + diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 8cf8709..46e2458 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -14,6 +14,9 @@ extern NSString * _Nonnull const KeyCachePolicy; extern NSString * _Nonnull const KeyCacheExpiry; +extern NSString * _Nonnull const KeyAppVelelCachePolicy; +extern NSString * _Nonnull const PageTypeOfflineFeedback; + //block returned when getting image //parameters are UIImage object for the image, NSData for gif images, UIImage object for the image, A BOOL to indicate if it is a fall back image. diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 57d48c2..ae6c4fd 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -19,6 +19,9 @@ NSString * _Nonnull const KeyCachePolicy = @"cachePolicy"; NSString * _Nonnull const KeyCacheExpiry = @"expiry"; +NSString * _Nonnull const KeyAppVelelCachePolicy = @"applicationLevelCache"; +NSString * _Nonnull const PageTypeOfflineFeedback = @"offlineFeedback"; + @interface MVMCoreCache () @@ -138,15 +141,6 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; return [self shouldPersistentlyCacheJSON:jsonDictionary]; } -- (BOOL)shouldSaveAtAppLevel:(nonnull NSDictionary *)jsonDictionary{ - - NSDictionary *cachePolicy = [jsonDictionary dict:KeyCachePolicy]; - if (![cachePolicy boolForKey:@"applicationLevelCache"] || ![self shouldPersistentlyCacheJSON:jsonDictionary]) { - return NO; - } - return true; -} - - (nullable NSURL *)getPathForPersistentCachePage:(nonnull NSString *)pageType isAppLevel:(BOOL)isAppLevel{ if (isAppLevel) { @@ -298,7 +292,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; - (void)addPageToPersistentCache:(nonnull NSDictionary *)jsonDictionary pageType:(nonnull NSString *)pageType expirationDate:(nonnull NSDate *)expirationDate{ NSError *error = nil; - [[PersistentCacheManager shared] saveWithData:jsonDictionary forKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:[self shouldSaveAtAppLevel:jsonDictionary]] expirationDate:expirationDate error:&error]; + [[PersistentCacheManager shared] saveWithData:jsonDictionary forKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:[self shouldSaveAtAppLevelWithInfoDictionary:jsonDictionary]] expirationDate:expirationDate error:&error]; if (error) { [[MVMCoreLoggingHandler sharedLoggingHandler] addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:[NSString stringWithFormat:@"%s_%@",__PRETTY_FUNCTION__,pageType]]]; }