Skip to content

Commit

Permalink
Store file value in cache on read
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Apr 19, 2024
1 parent 6d47c27 commit 64115c7
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,36 @@ extension Application {
}

do {
return try fileManager.in(path: path, filename: filename)
let storedValue: Value = try fileManager.in(path: path, filename: filename)

defer {
let setValue = {
shared.cache.set(
value: Application.State(
type: .state,
initial: storedValue,
scope: scope
),
forKey: scope.key
)
}

#if (!os(Linux) && !os(Windows))
if NSClassFromString("XCTest") == nil {
Task {
await MainActor.run {
setValue()
}
}
} else {
setValue()
}
#else
setValue()
#endif
}

return storedValue
} catch {
log(
error: error,
Expand Down

0 comments on commit 64115c7

Please sign in to comment.