<
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.type Effect.Effect = /*unresolved*/ anyEffect<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.type Scope.Scope = /*unresolved*/ anyScope>
readonly capacity: numbercapacity: number
readonly timeToLive?: Duration.Input | undefinedtimeToLive?: import DurationDuration.type Duration.Input = /*unresolved*/ anyInput | 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.type Effect.Effect = /*unresolved*/ anyEffect<
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.type Scope.Scope = /*unresolved*/ anyScope> : 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.type Scope.Scope = /*unresolved*/ anyScope
> =>
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
})