Digital PCT265 story MVAPCT-48 - More expiry logic fixes
This commit is contained in:
parent
4bdd93dbe5
commit
4fc4aa21f3
@ -59,7 +59,7 @@ public class CachedData: Codable {
|
||||
do {
|
||||
let dataToSave = try JSONEncoder().encode(cachedData)
|
||||
try dataToSave.write(to: filePath, options: .atomicWrite)
|
||||
} catch let error as EncodingError {
|
||||
} catch is EncodingError {
|
||||
throw CacheError.serializationFailed
|
||||
} catch {
|
||||
throw CacheError.saveFailed(error)
|
||||
@ -67,12 +67,12 @@ public class CachedData: Codable {
|
||||
}
|
||||
|
||||
@objc public func load(forKey key: String) throws -> [String: AnyHashable] {
|
||||
let keyNSString = NSString(string: key)
|
||||
let filePath = self.filePath(forKey: key)
|
||||
do {
|
||||
let data = try Data(contentsOf: filePath)
|
||||
let decodedCachedData = try JSONDecoder().decode(CachedData.self, from: data)
|
||||
if Date() < decodedCachedData.expirationDate {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: LOADED FROM PERSISTENT CACHE, key:\(key)")
|
||||
return decodedCachedData.data
|
||||
} else {
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: EXPIRED, key:\(key)")
|
||||
|
||||
@ -105,11 +105,11 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
||||
|
||||
- (BOOL)isJSONExpired:(nonnull NSDictionary *)jsonDictionary {
|
||||
NSDate *expirationDate = [self getExpirationDateForJSON:jsonDictionary];
|
||||
NSDate *today = [NSDate date];
|
||||
if (today > expirationDate) {
|
||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: NEW DATA ALREADY EXPIRED %@ %@ %@ %@",[jsonDictionary stringForKey:KeyPageType],[jsonDictionary stringForKey:@"moduleName"],today,expirationDate]];
|
||||
NSDate *now = [NSDate date];
|
||||
if ([now compare:expirationDate] == NSOrderedDescending) {
|
||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: NEW DATA ALREADY EXPIRED %@ now:%@ expirationDate:%@",jsonDictionary,now,expirationDate]];
|
||||
}
|
||||
return today > expirationDate;
|
||||
return [now compare:expirationDate] == NSOrderedDescending;
|
||||
}
|
||||
|
||||
- (nonnull NSDate *)getExpirationDateForJSON:(nonnull NSDictionary *)jsonDictionary {
|
||||
@ -123,7 +123,7 @@ static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
|
||||
if (!cachePolicy || ![cachePolicy boolForKey:@"persist"]) {
|
||||
return NO;
|
||||
}
|
||||
return [self isJSONExpired:jsonDictionary];
|
||||
return ![self isJSONExpired:jsonDictionary];
|
||||
}
|
||||
|
||||
- (BOOL)shouldPersistentlyCachePage:(nonnull NSDictionary *)jsonDictionary pageType:(nonnull NSString *)pageType {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user