Removed commented code
Also fixed file calling with appLevel flag.
This commit is contained in:
parent
2c66177f1a
commit
f6acae9afd
@ -55,7 +55,7 @@ public class CachedData: Codable {
|
|||||||
private override init() {}
|
private override init() {}
|
||||||
|
|
||||||
@objc public func save(data: [String: AnyHashable], forKey key: String, path: URL, expirationDate: Date) throws {
|
@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)
|
let cachedData = CachedData(data: data, expirationDate: expirationDate)
|
||||||
do {
|
do {
|
||||||
try FileManager.default.createDirectory(atPath: path.deletingLastPathComponent().relativePath, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.complete])
|
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] {
|
@objc public func load(forKey key: String, path: URL) throws -> [String: AnyHashable] {
|
||||||
do {
|
do {
|
||||||
print("Load Call**: \(path)")
|
//print("Load Call**: \(path)")
|
||||||
let data = try Data(contentsOf: path)
|
let data = try Data(contentsOf: path)
|
||||||
let decodedCachedData = try JSONDecoder().decode(CachedData.self, from: data)
|
let decodedCachedData = try JSONDecoder().decode(CachedData.self, from: data)
|
||||||
if Date() < decodedCachedData.expirationDate {
|
if Date() < decodedCachedData.expirationDate {
|
||||||
|
|||||||
@ -122,6 +122,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)shouldPersistentlyCacheJSON:(nonnull NSDictionary *)jsonDictionary {
|
- (BOOL)shouldPersistentlyCacheJSON:(nonnull NSDictionary *)jsonDictionary {
|
||||||
|
|
||||||
NSDictionary *cachePolicy = [jsonDictionary dict:KeyCachePolicy];
|
NSDictionary *cachePolicy = [jsonDictionary dict:KeyCachePolicy];
|
||||||
if (!cachePolicy || ![cachePolicy boolForKey:@"persist"]) {
|
if (!cachePolicy || ![cachePolicy boolForKey:@"persist"]) {
|
||||||
return NO;
|
return NO;
|
||||||
@ -187,16 +188,14 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
|||||||
|
|
||||||
- (NSDictionary * _Nullable)fetchPageFromPersistentCache:(nonnull NSString *)pageType {
|
- (NSDictionary * _Nullable)fetchPageFromPersistentCache:(nonnull NSString *)pageType {
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
// APP_CACHE
|
|
||||||
// if check in getPathForPersistentCachePage
|
NSDictionary *fileDataDictionary = [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:NO] error:&error];
|
||||||
// else getPathForPersistentAppCachePage
|
|
||||||
// return
|
|
||||||
NSMutableDictionary *fileDataDictionary = [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:YES] error:&error];
|
|
||||||
|
|
||||||
if (fileDataDictionary != nil) {
|
if (fileDataDictionary != nil) {
|
||||||
return fileDataDictionary;
|
return fileDataDictionary;
|
||||||
}else {
|
}else {
|
||||||
return [[PersistentCacheManager shared] loadForKey:pageType path:[self getPathForPersistentCachePage:pageType isAppLevel:YES] error:&error];
|
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 NSBlockOperation *weakOperation = addOperation;
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
[addOperation addExecutionBlock:^{
|
[addOperation addExecutionBlock:^{
|
||||||
|
|
||||||
if (!weakOperation.isCancelled) {
|
if (!weakOperation.isCancelled) {
|
||||||
|
|
||||||
// There must be a dictionary and page type to cache.
|
// 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.
|
// Adds json to cache with page type key.
|
||||||
[weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType];
|
[weakSelf.pageTypeCache setObject:jsonDictionary forKey:pageType];
|
||||||
|
|
||||||
|
NSLog(@"&&&&&PageType: %@", pageType);
|
||||||
if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) {
|
if (![self shouldPersistentlyCachePage:jsonDictionary pageType:pageType]) {
|
||||||
[[PersistentCacheManager shared] removeForKey:pageType error:nil];
|
[[PersistentCacheManager shared] removeForKey:pageType error:nil];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self addPageToPersistentCache:jsonDictionary pageType:pageType expirationDate:[self getExpirationDateForJSON:jsonDictionary] isApplicationLevel:[self shouldSaveAtAppLevel: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) {
|
if (completionBlock) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user