removed expiration hardcoded logic.

This commit is contained in:
mayur nilwant 2024-06-09 20:00:37 -04:00
parent 2d751b9d57
commit 2c66177f1a

View File

@ -50,12 +50,12 @@ 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: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}()
private let PageTypeOfflineFeedback = "offlineFeedback"
@objc public lazy var appLevelCacheDirectory = { fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}()
private override init() {}
@objc public func save(data: [String: AnyHashable], forKey key: String, path: URL, expirationDate: Date) throws {
print("Save Call**: \(path)")
let cachedData = CachedData(data: data, expirationDate: expirationDate)
do {
try FileManager.default.createDirectory(atPath: path.deletingLastPathComponent().relativePath, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.complete])
@ -71,10 +71,10 @@ public class CachedData: Codable {
@objc public func load(forKey key: String, path: URL) throws -> [String: AnyHashable] {
do {
print("Load Call**: \(path)")
let data = try Data(contentsOf: path)
let decodedCachedData = try JSONDecoder().decode(CachedData.self, from: data)
if Date() < decodedCachedData.expirationDate || key == PageTypeOfflineFeedback {
if Date() < decodedCachedData.expirationDate {
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "CACHEDFEED: LOADED FROM PERSISTENT CACHE, key:\(key), path:\(path)")
return decodedCachedData.data
} else {