From 2d751b9d57a2d68d34ba6b35434602d1e838126f Mon Sep 17 00:00:00 2001 From: mayur nilwant Date: Sun, 9 Jun 2024 10:58:07 -0400 Subject: [PATCH] Changed the location for offlineFeedbackForm from cache distionary to documents directory. Also added the logic if pageType = offlineFeeback then dis-regard expiration date, --- .../MVMCore/OtherHandlers/MVMCoreCache+Extension.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift index e0ff988..059dafb 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreCache+Extension.swift @@ -50,7 +50,8 @@ public class CachedData: Codable { @objc public static let shared = PersistentCacheManager() private let fileManager = FileManager.default @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() {} @@ -70,16 +71,17 @@ public class CachedData: Codable { @objc public func load(forKey key: String, path: URL) throws -> [String: AnyHashable] { do { + let data = try Data(contentsOf: path) 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)") return decodedCachedData.data } else { MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: EXPIRED, key:\(key), path:\(path)") throw CacheError.dataExpired } - } catch { + } catch (let error){ // Remove item from the cache on any failure. try fileManager.removeItem(at: path)