Open History to see the last commit
1import * as Cache from "effect/Cache";
2import * as Cause from "effect/Cause";
3import * as Effect from "effect/Effect";
4
5/**
6 * `Cache.get` for a caller that must not inherit another caller's interrupt.
7 *
8 * When a lookup's last caller is interrupted, `Cache` interrupts the lookup but
9 * keeps its entry until the lookup has stopped. A caller that arrives in that
10 * window joins the dying lookup and fails with a bare interrupt. The entry is
11 * gone by the time that failure arrives, so one more `get` starts a fresh
12 * lookup. A caller that was itself interrupted never reaches the retry.
13 */
14export const getCached = <Key, A, E, R>(
15 cache: Cache.Cache<Key, A, E, R>,
16 key: Key,
17): Effect.Effect<A, E, R> =>
18 Cache.get(cache, key).pipe(
19 Effect.catchCauseIf(Cause.hasInterruptsOnly, () => Cache.get(cache, key)),
20 );