Package: effect
Module: ScopedCache
Creates a ScopedCache with a fixed time-to-live for every lookup result.
When to use
Use to create a scoped cache when every cached lookup result should share the same lifetime.
Details
This is the constant-TTL variant of makeWith: values are acquired by the
lookup effect in per-entry scopes, capacity can evict older entries, and
entry scopes are closed when entries expire, are invalidated, are evicted, or
when the cache’s owning scope closes.
See
makeWith for computing time-to-live from each lookup result and keySignature
declare const make: <Key, A, E = never, R = never, ServiceMode extends "lookup" | "construction" = never>(options: { readonly lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>; readonly capacity: number; readonly timeToLive?: Duration.Input | undefined; readonly requireServicesAt?: ServiceMode | undefined; }) => Effect.Effect<ScopedCache<Key, A, E, "lookup" extends ServiceMode ? Exclude<R, Scope.Scope> : never>, never, ("lookup" extends ServiceMode ? never : R) | Scope.Scope>
Since v2.0.0