clean up vars
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
eeefcf19b7
commit
a6679a56e9
@ -10,6 +10,8 @@ import UIKit
|
|||||||
|
|
||||||
/// A service that handles image caching using memory, disk, and network in priority order.
|
/// A service that handles image caching using memory, disk, and network in priority order.
|
||||||
public class EmployeeCacheService {
|
public class EmployeeCacheService {
|
||||||
|
private lazy var fileURL = cacheDirectory.appendingPathComponent("employees.json")
|
||||||
|
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
public static let shared = EmployeeCacheService() // Default shared instance
|
public static let shared = EmployeeCacheService() // Default shared instance
|
||||||
|
|
||||||
@ -30,15 +32,15 @@ public class EmployeeCacheService {
|
|||||||
|
|
||||||
public func save(from employees: Employees) throws {
|
public func save(from employees: Employees) throws {
|
||||||
let data = try JSONEncoder().encode(employees)
|
let data = try JSONEncoder().encode(employees)
|
||||||
try data.write(to: cacheDirectory.appendingPathComponent("employees.json"))
|
try data.write(to: fileURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func load() throws -> Employees {
|
public func load() throws -> Employees {
|
||||||
let data = try Data(contentsOf: cacheDirectory.appendingPathComponent("employees.json"))
|
let data = try Data(contentsOf: fileURL)
|
||||||
return try JSONDecoder().decode(Employees.self, from: data)
|
return try JSONDecoder().decode(Employees.self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func clear() {
|
public func clear() {
|
||||||
try? FileManager.default.removeItem(at: cacheDirectory.appendingPathComponent("employees.json"))
|
try? FileManager.default.removeItem(at: fileURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user