MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeCache

Function makeCache

packages/effect/src/ui/Query.ts:4538–4561  ·  view source on GitHub ↗
(options: {
  readonly visibility: Signal
  readonly connectivity: Signal
  /** The problems sink. A throw from it is swallowed. */
  readonly report: (problem: Problem.Any) => void
  /** In milliseconds, from `cacheIdleMs`. */
  readonly idleMs: number
  /**
   * The server's per-request mode: an entry settles at most once and is never
   * stale after, every settle is stored, a query's own `invalidate` is ignored
   * and reported, and no idle timer, interval or host edge runs.
   */
  readonly settleOnce?: boolean | undefined
  /** `false`: no fetch ever starts, as on a server render with a budget of 0. */
  readonly fetches?: boolean | undefined
})

Source from the content-addressed store, hash-verified

4536 * @internal
4537 */
4538export const makeCache = (options: {
4539 readonly visibility: Signal
4540 readonly connectivity: Signal
4541 /** The problems sink. A throw from it is swallowed. */
4542 readonly report: (problem: Problem.Any) => void
4543 /** In milliseconds, from `cacheIdleMs`. */
4544 readonly idleMs: number
4545 /**
4546 * The server's per-request mode: an entry settles at most once and is never
4547 * stale after, every settle is stored, a query's own `invalidate` is ignored
4548 * and reported, and no idle timer, interval or host edge runs.
4549 */
4550 readonly settleOnce?: boolean | undefined
4551 /** `false`: no fetch ever starts, as on a server render with a budget of 0. */
4552 readonly fetches?: boolean | undefined
4553}): Effect.Effect<CacheInternals, never, Scope.Scope> =>
4554 Effect.map(
4555 // Uninterruptible from the build to the finalizer's registration, so no build goes without disposal.
4556 Effect.acquireRelease(
4557 Effect.contextWith((context: Context.Context<never>) => Effect.sync(() => buildCache(context, options))),
4558 (built) => built.dispose
4559 ),
4560 (built) => built.cache
4561 )
4562
4563const cacheIdleMs = (input: Duration.Input | undefined): number => {
4564 const duration = Duration.fromInputUnsafe(input ?? "5 minutes")

Callers 1

layerFunction · 0.70

Calls 3

buildCacheFunction · 0.85
mapMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected