diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift index 69d4d53..3522b3a 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift @@ -55,7 +55,7 @@ public class CachedData: Codable { private override init() {} @objc public func save(data: [String: AnyHashable], forKey key: String, path: URL, expirationDate: Date) throws { - print("Save Call**: \(path)") + //print("Save Call**: \(path)") let cachedData = CachedData(data: data, expirationDate: expirationDate) do { try FileManager.default.createDirectory(atPath: path.deletingLastPathComponent().relativePath, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.complete]) @@ -71,7 +71,7 @@ public class CachedData: Codable { @objc public func load(forKey key: String, path: URL) throws -> [String: AnyHashable] { do { - print("Load Call**: \(path)") + //print("Load Call**: \(path)") let data = try Data(contentsOf: path) let decodedCachedData = try JSONDecoder().decode(CachedData.self, from: data) if Date() < decodedCachedData.expirationDate { diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m index 132a9ee..e412d38 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache.m @@ -122,6 +122,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; } - (BOOL)shouldPersistentlyCacheJSON:(nonnull NSDictionary *)jsonDictionary { + NSDictionary *cachePolicy = [jsonDictionary dict:KeyCachePolicy]; if (!cachePolicy || ![cachePolicy boolForKey:@"persist"]) { return NO; @@ -187,16 +188,14 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; - (NSDictionary * _Nullable)fetchPageFromPersistentCache:(nonnull NSString *)pageType { 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]; + + NSDictionary *fileDataDictionary = [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:NO] error:&error]; if (fileDataDictionary != nil) { return fileDataDictionary; }else { return [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:YES] error:&error]; + } } @@ -325,7 +324,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; __weak NSBlockOperation *weakOperation = addOperation; __weak typeof(self) weakSelf = self; [addOperation addExecutionBlock:^{ - + if (!weakOperation.isCancelled) { // There must be a dictionary and page type to cache. @@ -340,21 +339,13 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt"; // Adds json to cache with page type key. [weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType]; + NSLog(@"&&&&&PageType: %@", pageType); if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) { [[PersistentCacheManager shared] removeForKey:pageType error:nil]; return; } [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) {