Skip to content

Commit

Permalink
Store file value in cache on read (#101)
Browse files Browse the repository at this point in the history
* Store file value in cache on read

* Change state type to file
  • Loading branch information
0xLeif authored Apr 25, 2024
1 parent 7810c3e commit cb2eebd
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: .file,
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 cb2eebd

Please sign in to comment.