removed expiration hardcoded logic.
This commit is contained in:
parent
2d751b9d57
commit
2c66177f1a
@ -50,12 +50,12 @@ 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: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}()
|
@objc public lazy var appLevelCacheDirectory = { fileManager.urls(for: .cachesDirectory, in: .userDomainMask).first!.appendingPathComponent("AppAtomic")}()
|
||||||
private let PageTypeOfflineFeedback = "offlineFeedback"
|
|
||||||
|
|
||||||
private override init() {}
|
private override init() {}
|
||||||
|
|
||||||
@objc public func save(data: [String: AnyHashable], forKey key: String, path: URL, expirationDate: Date) throws {
|
@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)
|
let cachedData = CachedData(data: data, expirationDate: expirationDate)
|
||||||
do {
|
do {
|
||||||
try FileManager.default.createDirectory(atPath: path.deletingLastPathComponent().relativePath, withIntermediateDirectories: true, attributes: [.protectionKey: FileProtectionType.complete])
|
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] {
|
@objc public func load(forKey key: String, path: URL) throws -> [String: AnyHashable] {
|
||||||
do {
|
do {
|
||||||
|
print("Load Call**: \(path)")
|
||||||
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 || key == PageTypeOfflineFeedback {
|
if Date() < decodedCachedData.expirationDate {
|
||||||
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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user