<
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
>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.
export const 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
>
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.
make = <
function (type parameter) Key in <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>
Key,
function (type parameter) A in <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>
A,
function (type parameter) E in <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>
E = never,
function (type parameter) R in <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>
R = never,
function (type parameter) ServiceMode in <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>
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
}
options: {
readonly lookup: (
key: Key
) => Effect.Effect<A, E, R | Scope.Scope>
lookup: (key: Keykey: function (type parameter) Key in <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>
Key) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <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>
A, function (type parameter) E in <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>
E, function (type parameter) R in <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>
R | import ScopeScope.Scope>
readonly capacity: numbercapacity: number
readonly timeToLive?: Duration.Input | undefinedtimeToLive?: import DurationDuration.type Input =
| number
| bigint
| Duration.Duration
| readonly [seconds: number, nanos: number]
| `${number} nano`
| `${number} nanos`
| `${number} micro`
| `${number} micros`
| `${number} milli`
| `${number} millis`
| `${number} second`
| `${number} seconds`
| `${number} minute`
| `${number} minutes`
| `${number} hour`
| `${number} hours`
| `${number} day`
| `${number} days`
| `${number} week`
| `${number} weeks`
| "Infinity"
| "-Infinity"
| Duration.DurationObject
Valid input types that can be converted to a Duration.
When to use
Use when an API should accept any value that Effect can convert into a
Duration, including existing durations, millisecond numbers, nanosecond
bigints, high-resolution tuples, duration strings, infinity strings, or
duration objects.
Details
String inputs accept values like "10 seconds", "500 millis",
"Infinity", and "-Infinity". Finite fractional values that are
normalized to nanoseconds are rounded to the nearest nanosecond, with ties
away from zero.
Input | undefined
readonly requireServicesAt?: ServiceMode | undefinedrequireServicesAt?: function (type parameter) ServiceMode in <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>
ServiceMode | undefined
}
): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
interface ScopedCache<in out Key, in out A, in out E = never, out R = never>A scoped cache whose values are acquired by a lookup effect and stored in
per-entry scopes.
When to use
Use to cache values that acquire scoped resources and must release those
resources when entries expire, are evicted, or are invalidated.
Details
Concurrent requests for the same key share the same in-flight lookup.
Entries can expire based on the lookup exit, are evicted when capacity is
exceeded, and release their entry scopes when invalidated, evicted, expired,
or when the cache's owning scope closes.
ScopedCache<function (type parameter) Key in <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>
Key, function (type parameter) A in <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>
A, function (type parameter) E in <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>
E, "lookup" extends function (type parameter) ServiceMode in <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>
ServiceMode ? type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) R in <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>
R, import ScopeScope.Scope> : never>,
never,
("lookup" extends function (type parameter) ServiceMode in <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>
ServiceMode ? never : function (type parameter) R in <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>
R) | import ScopeScope.Scope
> =>
const makeWith: <
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?:
| ((
exit: Exit.Exit<A, E>,
key: Key
) => 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
>
Creates a ScopedCache from a lookup function, maximum capacity, and a
time-to-live function computed from each lookup exit and key.
When to use
Use when you need a scoped cache whose entry lifetime depends on each lookup
result or key.
Details
The cache must be constructed in a Scope. Each lookup runs in its own entry
scope, and that scope is closed when the entry expires, is invalidated, is
evicted by capacity, or when the cache's owning scope closes.
requireServicesAt controls whether lookup services are captured at
construction time or required when lookup operations run.
makeWith<function (type parameter) Key in <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>
Key, function (type parameter) A in <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>
A, function (type parameter) E in <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>
E, function (type parameter) R in <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>
R, function (type parameter) ServiceMode in <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>
ServiceMode>({
...options: {
readonly lookup: (
key: Key
) => Effect.Effect<A, E, R | Scope.Scope>
readonly capacity: number
readonly timeToLive?: Duration.Input | undefined
readonly requireServicesAt?:
| ServiceMode
| undefined
}
options,
timeToLive?: | (<A, E>(
_: Exit.Exit<A, E>,
_key: unknown
) => Duration.Duration)
| (() => Duration.Input)
timeToLive: options: {
readonly lookup: (
key: Key
) => Effect.Effect<A, E, R | Scope.Scope>
readonly capacity: number
readonly timeToLive?: Duration.Input | undefined
readonly requireServicesAt?:
| ServiceMode
| undefined
}
options.timeToLive?: Duration.Input | undefinedtimeToLive ? () => options: {
readonly lookup: (
key: Key
) => Effect.Effect<A, E, R | Scope.Scope>
readonly capacity: number
readonly timeToLive?: Duration.Input | undefined
readonly requireServicesAt?:
| ServiceMode
| undefined
}
options.timeToLive?: Duration.Input | undefinedtimeToLive! : const defaultTimeToLive: <A, E>(
_: Exit.Exit<A, E>,
_key: unknown
) => Duration.Duration
defaultTimeToLive
})