Converted shouldSaveAtAppLevelWithInfoDictionary to swift from objective-c

This commit is contained in:
mayur nilwant 2024-06-11 20:09:03 -04:00
parent 37a9cea3f4
commit b64602939d
3 changed files with 23 additions and 10 deletions

View File

@ -134,3 +134,19 @@ extension PersistentCacheManager {
}
}
@objc public extension MVMCoreCache {
@objc func shouldSaveAtAppLevel(infoDictionary:[String: AnyHashable]) -> Bool {
guard let cachePolicy = infoDictionary[KeyCachePolicy] as? Dictionary<String, Any>,
let appLevelKey = cachePolicy[KeyAppVelelCachePolicy] as? Bool,
appLevelKey == true,
self.shouldCachePageJSON(infoDictionary, pageType: PageTypeOfflineFeedback) == true,
self.isJSONExpired(infoDictionary) == false else {return false}
return true
}
}

View File

@ -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.

View File

@ -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]]];
}