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