From 8a92c9cdd320ddae966b696a00f8f3c3af382420 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Wed, 5 Jun 2024 12:29:41 -0400 Subject: [PATCH 1/2] removing dead references --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index 5c113a1..c68b43d 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -293,7 +293,6 @@ AFBB96AE1FBA3B590008D868 /* MVMCoreGetterUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreGetterUtility.h; sourceTree = ""; }; AFBB96AF1FBA3B590008D868 /* MVMCoreGetterUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreGetterUtility.m; sourceTree = ""; }; AFBB96B51FBA3CEC0008D868 /* MVMCoreActionDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreActionDelegateProtocol.h; sourceTree = ""; }; - AFBB96D21FBA44420008D868 /* VZWAuthentication.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VZWAuthentication.framework; path = ../../SharedFrameworks/VZWAuthentication.framework; sourceTree = ""; }; AFBB96E91FBA4A260008D868 /* MFHardCodedServerResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFHardCodedServerResponse.h; sourceTree = ""; }; AFBB96EA1FBA4A260008D868 /* MFHardCodedServerResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFHardCodedServerResponse.m; sourceTree = ""; }; AFEA17A6209B6A1C00BC6740 /* MVMCoreBlockOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreBlockOperation.h; sourceTree = ""; }; @@ -651,7 +650,6 @@ AF43A6FC1FBE2F2A008E9347 /* Reachability */, AF43A5C01FBB76D5008E9347 /* CoreGraphics.framework */, AF43A5BF1FBB76C3008E9347 /* UIKit.framework */, - AFBB96D21FBA44420008D868 /* VZWAuthentication.framework */, ); name = Frameworks; sourceTree = ""; From b31c97237c441664cf4a8be1c4b01194a36f1272 Mon Sep 17 00:00:00 2001 From: mayur nilwant Date: Fri, 7 Jun 2024 16:49:02 -0400 Subject: [PATCH 2/2] 1. Written logic to analyze app level page type and store it accordingly in different directory. 2 Also implemented logic to fetch from app level or user level. --- .../MVMCoreCache+Extension.swift | 1 + MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h | 6 ++- MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m | 52 ++++++++++++++++--- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift index 7210021..e0ff988 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift @@ -50,6 +50,7 @@ public class CachedData: Codable { @objc public static let shared = PersistentCacheManager() private let fileManager = FileManager.default @objc public lazy var cacheDirectory = { fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("Atomic")}() + @objc public lazy var appLevelCacheDirectory = { fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}() private override init() {} diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h index 5d2a48c..bc56be9 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.h @@ -51,8 +51,9 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO /// Checks if the module is to be persistently cached. - (BOOL)shouldPersistentlyCacheModule:(nonnull NSDictionary *)jsonDictionary module:(nonnull NSString *)module; -/// Can override the path for the page to be cached. Currently Cache/Atomic/Pages/pageType -- (nullable NSURL *)getPathForPersistentCachePage:(nonnull NSString *)pageType; + +/// Can override the path for the page to be cached at app level and user level. Currently Cache/* +- (nullable NSURL *)getPathForPersistentCachePage:(nonnull NSString *)pageType isAppLevel:(BOOL)isAppLevel; /// Can override the path for the page to be cached. Currently Cache/Atomic/Modules/moduleName - (nullable NSURL *)getPathForPersistentCacheModule:(nonnull NSString *)moduleName; @@ -198,5 +199,6 @@ typedef void(^MVMCoreGetImageBlock)(UIImage * _Nullable, NSData * _Nullable, BOO /// Loads an AVPlayerAsset from the shared asset cache. - (void)playerAssetFromFileName:(nonnull NSString *)filename trackKeys:(nonnull NSArray *)trackKeys onComplete:(void(^_Nonnull)(AVAsset * _Nullable, NSString * _Nonnull, MVMCoreErrorObject * _Nullable))completionHandler; +- (BOOL)shouldSaveAtAppLevel:(nonnull NSDictionary *)jsonDictionary; @end diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 4f90380..132a9ee 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -137,8 +137,22 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; return [self shouldPersistentlyCacheJSON:jsonDictionary]; } -- (nullable NSURL *)getPathForPersistentCachePage:(nonnull NSString *)pageType { - return [[[[PersistentCacheManager shared].cacheDirectory URLByAppendingPathComponent:@"Pages"] URLByAppendingPathComponent:pageType] URLByAppendingPathExtension:@"json"]; +- (BOOL)shouldSaveAtAppLevel:(nonnull NSDictionary *)jsonDictionary{ + + NSDictionary *cachePolicy = [jsonDictionary dict:KeyCachePolicy]; + if (!cachePolicy || ![cachePolicy boolForKey:@"persist"] || ![cachePolicy boolForKey:@"applicationLevelCache"]) { + return NO; + } + return true; +} + +- (nullable NSURL *)getPathForPersistentCachePage:(nonnull NSString *)pageType isAppLevel:(BOOL)isAppLevel{ + + if (isAppLevel) { + return [[[[PersistentCacheManager shared].appLevelCacheDirectory URLByAppendingPathComponent:@"Pages"] URLByAppendingPathComponent:pageType] URLByAppendingPathExtension:@"json"]; + } else { + return [[[[PersistentCacheManager shared].cacheDirectory URLByAppendingPathComponent:@"Pages"] URLByAppendingPathComponent:pageType] URLByAppendingPathExtension:@"json"]; + } } - (nullable NSURL *)getPathForPersistentCacheModule:(nonnull NSString *)moduleName { @@ -172,8 +186,18 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } - (NSDictionary * _Nullable)fetchPageFromPersistentCache:(nonnull NSString *)pageType { - NSError *error = nil; - return [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType] error:&error]; + NSError *error = nil; + // APP_CACHE + // if check in getPathForPersistentCachePage + // else getPathForPersistentAppCachePage + // return + NSMutableDictionary *fileDataDictionary = [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:YES] error:&error]; + + if (fileDataDictionary != nil) { + return fileDataDictionary; + }else { + return [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:YES] error:&error]; + } } - (NSDictionary * _Nullable)fetchModuleFromPersistentCache:(nonnull NSString *)moduleName { @@ -270,9 +294,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; [self addModulesToCache:jsonDictionary queue:nil waitUntilFinished:NO completionBlock:NULL]; } -- (void)addPageToPersistentCache:(nonnull NSDictionary *)jsonDictionary pageType:(nonnull NSString *)pageType expirationDate:(nonnull NSDate *)expirationDate { + + +- (void)addPageToPersistentCache:(nonnull NSDictionary *)jsonDictionary pageType:(nonnull NSString *)pageType expirationDate:(nonnull NSDate *)expirationDate isApplicationLevel:(BOOL)isApplicationLevel { NSError *error = nil; - [[PersistentCacheManager shared] saveWithData:jsonDictionary forKey:pageType path:[self getPathForPersistentCachePage:pageType] expirationDate:expirationDate error:&error]; + [[PersistentCacheManager shared] saveWithData:jsonDictionary forKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:isApplicationLevel] expirationDate:expirationDate error:&error]; if (error) { [[MVMCoreLoggingHandler sharedLoggingHandler] addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:[NSString stringWithFormat:@"%s_%@",__PRETTY_FUNCTION__,pageType]]]; } @@ -314,11 +340,21 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // Adds json to cache with page type key. [weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType]; - if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) { + if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) { [[PersistentCacheManager shared] removeForKey:pageType error:nil]; return; } - [self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary]]; + + [self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary] isApplicationLevel:[self shouldSaveAtAppLevel:jsonDictionary]]; + +// if ([self shouldSaveAtAppLevel:jsonDictionary]) { +// //[self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:expirationDate isApplicationLevel:YES]; +// [self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary] isApplicationLevel:YES]; +// +// } else { +// // [self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:expirationDate isApplicationLevel:NO]; +// } + } } if (completionBlock) {