Skip to content

Commit

Permalink
1.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Jun 16, 2024
1 parent fd98252 commit 84f755d
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ public extension SecureCacheService {
guard let dateString = try await load(for: key) else { return nil }
return dateFormatter.date(from: dateString)
}

@_disfavoredOverload
func save(_ value: Encodable?, for key: SecureCacheServiceKey, encoder: JSONEncoder = JSONEncoder()) async throws {
guard let value else {
try await save(nil as String?, for: key)
return
}
let data = try encoder.encode(value)
guard let string = String(data: data, encoding: .utf8) else { throw Errors.custom("Invalid UTF8 data") }
try await save(string, for: key)
}

@_disfavoredOverload
func load<T: Decodable>(for key: SecureCacheServiceKey, decoder: JSONDecoder = JSONDecoder()) async throws -> T? {
guard let string = try await load(for: key) else { return nil }
guard let data = string.data(using: .utf8) else { throw Errors.custom("Invalid UTF8 string") }
return try decoder.decode(T.self, from: data)
}
}

public final actor MockSecureCacheService: SecureCacheService {
Expand Down

0 comments on commit 84f755d

Please sign in to comment.