diff options
| author | Kit Langton <[email protected]> | 2026-03-26 14:05:47 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-26 18:05:47 +0000 |
| commit | 1ebc92fd36837b1e31e7dbab52f378cd62aa7157 (patch) | |
| tree | 140629225119db0c68a6bd33df3352c3ae8950b7 /packages | |
| parent | 9f94bdb49634bda90a2804585b8d739228dde876 (diff) | |
| download | opencode-1ebc92fd36837b1e31e7dbab52f378cd62aa7157.tar.gz opencode-1ebc92fd36837b1e31e7dbab52f378cd62aa7157.zip | |
refactor(config): use cachedInvalidateWithTTL, bump effect to beta.37 (#19322)
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/config/config.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 645ae8814..67f298b42 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -40,7 +40,7 @@ import { Lock } from "@/util/lock" import { AppFileSystem } from "@/filesystem" import { InstanceState } from "@/effect/instance-state" import { makeRuntime } from "@/effect/run-service" -import { Effect, Layer, ServiceMap } from "effect" +import { Duration, Effect, Layer, ServiceMap } from "effect" export namespace Config { const ModelId = z.string().meta({ $ref: "https://models.dev/model-schema.json#/$defs/Model" }) @@ -1241,7 +1241,15 @@ export namespace Config { return result }) - let cachedGlobal = yield* Effect.cached(loadGlobal().pipe(Effect.orElseSucceed(() => ({}) as Info))) + const [cachedGlobal, invalidateGlobal] = yield* Effect.cachedInvalidateWithTTL( + loadGlobal().pipe( + Effect.tapError((error) => + Effect.sync(() => log.error("failed to load global config, using defaults", { error: String(error) })), + ), + Effect.orElseSucceed((): Info => ({})), + ), + Duration.infinity, + ) const getGlobal = Effect.fn("Config.getGlobal")(function* () { return yield* cachedGlobal @@ -1446,7 +1454,7 @@ export namespace Config { }) const invalidate = Effect.fn("Config.invalidate")(function* (wait?: boolean) { - cachedGlobal = yield* Effect.cached(loadGlobal().pipe(Effect.orElseSucceed(() => ({}) as Info))) + yield* invalidateGlobal const task = Instance.disposeAll() .catch(() => undefined) .finally(() => |
