Changed the location for offlineFeedbackForm from cache distionary to documents directory.
Also added the logic if pageType = offlineFeeback then dis-regard expiration date,
This commit is contained in:
parent
e76313da4e
commit
2d751b9d57
@ -50,7 +50,8 @@ public class CachedData: Codable {
|
|||||||
@objc public static let shared = PersistentCacheManager()
|
@objc public static let shared = PersistentCacheManager()
|
||||||
private let fileManager = FileManager.default
|
private let fileManager = FileManager.default
|
||||||
@objc public lazy var cacheDirectory = { fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("Atomic")}()
|
@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")}()
|
@objc public lazy var appLevelCacheDirectory = { fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}()
|
||||||
|
private let PageTypeOfflineFeedback = "offlineFeedback"
|
||||||
|
|
||||||
private override init() {}
|
private override init() {}
|
||||||
|
|
||||||
@ -70,16 +71,17 @@ 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 {
|
||||||
|
|
||||||
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 || key == PageTypeOfflineFeedback {
|
||||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: LOADED FROM PERSISTENT CACHE, key:\(key), path:\(path)")
|
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: LOADED FROM PERSISTENT CACHE, key:\(key), path:\(path)")
|
||||||
return decodedCachedData.data
|
return decodedCachedData.data
|
||||||
} else {
|
} else {
|
||||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: EXPIRED, key:\(key), path:\(path)")
|
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: EXPIRED, key:\(key), path:\(path)")
|
||||||
throw CacheError.dataExpired
|
throw CacheError.dataExpired
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (let error){
|
||||||
// Remove item from the cache on any failure.
|
// Remove item from the cache on any failure.
|
||||||
try fileManager.removeItem(at: path)
|
try fileManager.removeItem(at: path)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user