ScopedCache<Key, A, E, R>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.
export interface 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<in out function (type parameter) Key in ScopedCache<in out Key, in out A, in out E = never, out R = never>Key, in out function (type parameter) A in ScopedCache<in out Key, in out A, in out E = never, out R = never>A, in out function (type parameter) E in ScopedCache<in out Key, in out A, in out E = never, out R = never>E = never, out function (type parameter) R in ScopedCache<in out Key, in out A, in out E = never, out R = never>R = never> extends Pipeable {
readonly [const TypeId: "~effect/ScopedCache"TypeId]: typeof const TypeId: "~effect/ScopedCache"TypeId
ScopedCache<in out Key, in out A, in out E = never, out R = never>.state: State<Key, A, E>state: type State<K, A, E> =
| {
readonly _tag: "Open"
readonly map: MutableHashMap.MutableHashMap<
K,
Entry<A, E>
>
}
| {
readonly _tag: "Closed"
}
Represents whether a ScopedCache is open or closed.
When to use
Use when inspecting the low-level lifecycle state of a scoped cache.
Details
Open stores cached entries in access order for reuse and eviction.
Closed means the owning scope has closed and the cache can no longer
perform lookup operations.
State<function (type parameter) Key in ScopedCache<in out Key, in out A, in out E = never, out R = never>Key, function (type parameter) A in ScopedCache<in out Key, in out A, in out E = never, out R = never>A, function (type parameter) E in ScopedCache<in out Key, in out A, in out E = never, out R = never>E>
readonly ScopedCache<in out Key, in out A, in out E = never, out R = never>.capacity: numbercapacity: number
readonly ScopedCache<in out Key, in out A, in out E = never, out R = never>.lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>lookup: (key: in out Keykey: function (type parameter) Key in ScopedCache<in out Key, in out A, in out E = never, out R = never>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 ScopedCache<in out Key, in out A, in out E = never, out R = never>A, function (type parameter) E in ScopedCache<in out Key, in out A, in out E = never, out R = never>E, function (type parameter) R in ScopedCache<in out Key, in out A, in out E = never, out R = never>R | import ScopeScope.Scope>
readonly ScopedCache<in out Key, in out A, in out E = never, out R = never>.timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.DurationtimeToLive: (exit: Exit.Exit<A, E>exit: import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<function (type parameter) A in ScopedCache<in out Key, in out A, in out E = never, out R = never>A, function (type parameter) E in ScopedCache<in out Key, in out A, in out E = never, out R = never>E>, key: in out Keykey: function (type parameter) Key in ScopedCache<in out Key, in out A, in out E = never, out R = never>Key) => import DurationDuration.Duration
}