<Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(
self: ScopedCache<Key, A, E, R>
) => Effect.Effect<boolean>
<Key, A, E, R>(
self: ScopedCache<Key, A, E, R>,
key: Key,
f: Predicate.Predicate<A>
): Effect.Effect<boolean>Invalidates the entry associated with the specified key in the cache when the predicate returns true for the cached value.
When to use
Use to remove an already-cached scoped value only when the successful cached value satisfies a predicate.
Details
Returns true only when a successful cached value matches and is removed. It
returns false for absent, expired, failed, or non-matching entries.
Gotchas
A matching invalidation closes the entry scope and releases its resources.
export const const invalidateWhen: {
<Key, A>(key: Key, f: Predicate.Predicate<A>): <
E,
R
>(
self: ScopedCache<Key, A, E, R>
) => Effect.Effect<boolean>
<Key, A, E, R>(
self: ScopedCache<Key, A, E, R>,
key: Key,
f: Predicate.Predicate<A>
): Effect.Effect<boolean>
}
Invalidates the entry associated with the specified key in the cache when the
predicate returns true for the cached value.
When to use
Use to remove an already-cached scoped value only when the successful cached
value satisfies a predicate.
Details
Returns true only when a successful cached value matches and is removed. It
returns false for absent, expired, failed, or non-matching entries.
Gotchas
A matching invalidation closes the entry scope and releases its resources.
invalidateWhen: {
<function (type parameter) Key in <Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>Key, function (type parameter) A in <Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>A>(key: Keykey: function (type parameter) Key in <Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>Key, f: Predicate.Predicate<A>f: import PredicatePredicate.type Predicate.Predicate = /*unresolved*/ anyPredicate<function (type parameter) A in <Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>A>): <function (type parameter) E in <E, R>(self: ScopedCache<Key, A, E, R>): Effect.Effect<boolean>E, function (type parameter) R in <E, R>(self: ScopedCache<Key, A, E, R>): Effect.Effect<boolean>R>(self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: 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>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>Key, function (type parameter) A in <Key, A>(key: Key, f: Predicate.Predicate<A>): <E, R>(self: ScopedCache<Key, A, E, R>) => Effect.Effect<boolean>A, function (type parameter) E in <E, R>(self: ScopedCache<Key, A, E, R>): Effect.Effect<boolean>E, function (type parameter) R in <E, R>(self: ScopedCache<Key, A, E, R>): Effect.Effect<boolean>R>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
<function (type parameter) Key in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>R>(self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: 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, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>R>, key: Keykey: function (type parameter) Key in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, f: Predicate.Predicate<A>f: import PredicatePredicate.type Predicate.Predicate = /*unresolved*/ anyPredicate<function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean>
} = import dualdual(
3,
<function (type parameter) Key in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>R>(self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: 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, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A, function (type parameter) E in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>E, function (type parameter) R in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>R>, key: Keykey: function (type parameter) Key in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>Key, f: Predicate.Predicate<A>f: import PredicatePredicate.type Predicate.Predicate = /*unresolved*/ anyPredicate<function (type parameter) A in <Key, A, E, R>(self: ScopedCache<Key, A, E, R>, key: Key, f: Predicate.Predicate<A>): Effect.Effect<boolean>A>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean> =>
import effecteffect.const uninterruptibleMask: <A, E, R>(
f: (
restore: <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
uninterruptibleMask((restore: <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
restore) =>
import corecore.const withFiber: <
A,
E = never,
R = never
>(
evaluate: (
fiber: FiberImpl<unknown, unknown>
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
withFiber((fiber: effect.FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit.Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit.Exit<unknown, unknown> | undefined;
evaluate: (effect: core.Primitive) => void;
runLoop: (effect: core.Primitive) => typeof core.Yield | Exit.Exit<unknown, unknown>;
getCont: <S extends core.contA | core.contE>(symbol: S) => (core.Primitive & Record<S, (value: any, fiber: effect.FiberImpl) => core.Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => core.Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber) =>
import effecteffect.const flatMap: {
<A, B, E2, R2>(
f: (a: A) => Effect.Effect<B, E2, R2>
): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (a: A) => Effect.Effect<B, E2, R2>
): Effect.Effect<B, E | E2, R | R2>
}
flatMap(const getImpl: <Key, A, E, R>(
self: ScopedCache<Key, A, E, R>,
key: Key,
fiber: Fiber.Fiber<any, any>,
isRead?: boolean
) => Effect.Effect<Entry<A, E> | undefined>
getImpl(self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self, key: Keykey, fiber: effect.FiberImpl<unknown, unknown>(parameter) fiber: {
id: number;
interruptible: boolean;
currentOpCount: number;
currentLoopCount: number;
_stack: Array<Primitive>;
_observers: Array<(exit: Exit.Exit<A, E>) => void>;
_exit: Exit.Exit<A, E> | undefined;
_currentExit: Exit.Exit<A, E> | undefined;
_children: Set<FiberImpl<any, any>> | undefined;
_interruptedCause: Cause.Cause<never> | undefined;
_yielded: Exit.Exit<any, any> | (() => void) | undefined;
context: Context.Context<never>;
currentScheduler: Scheduler.Scheduler;
currentTracerContext: Tracer.Tracer["context"];
currentSpan: Tracer.AnySpan | undefined;
currentLogLevel: LogLevel.LogLevel;
minimumLogLevel: LogLevel.LogLevel;
currentStackFrame: StackFrame | undefined;
runtimeMetrics: Metric.FiberRuntimeMetricsService | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
_dispatcher: Scheduler.SchedulerDispatcher | undefined;
currentDispatcher: SchedulerDispatcher;
getRef: <X>(ref: Context.Reference<X>) => X;
addObserver: (cb: (exit: Exit.Exit<unknown, unknown>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit.Exit<unknown, unknown> | undefined;
evaluate: (effect: core.Primitive) => void;
runLoop: (effect: core.Primitive) => typeof core.Yield | Exit.Exit<unknown, unknown>;
getCont: <S extends core.contA | core.contE>(symbol: S) => (core.Primitive & Record<S, (value: any, fiber: effect.FiberImpl) => core.Primitive>) | undefined;
yieldWith: (value: Exit.Exit<any, any> | (() => void)) => core.Yield;
children: () => Set<Fiber.Fiber<any, any>>;
pipe: () => unknown;
setContext: (context: Context.Context<never>) => void;
currentSpanLocal: Span | undefined;
}
fiber, false), (entry: unknownentry) => {
if (entry: unknownentry === var undefinedundefined) {
return import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false)
}
return restore: <A, E, R>(
effect: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
restore(import DeferredDeferred.await(entry: Entry<A, E>entry.deferred)).pipe(
import effecteffect.const flatMap: {
<A, B, E2, R2>(
f: (a: A) => Effect.Effect<B, E2, R2>
): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (a: A) => Effect.Effect<B, E2, R2>
): Effect.Effect<B, E | E2, R | R2>
}
flatMap((value: unknownvalue) => {
if (self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.ScopedCache<Key, A, E, R>.state: State<Key, A, E>state._tag: "Open" | "Closed"_tag === "Closed") {
return import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false)
} else if (f: Predicate.Predicate<A>f(value: unknownvalue)) {
import MutableHashMapMutableHashMap.remove(self: ScopedCache<Key, A, E, R>(parameter) self: {
state: State<Key, A, E>;
capacity: number;
lookup: (key: Key) => Effect.Effect<A, E, R | Scope.Scope>;
timeToLive: (exit: Exit.Exit<A, E>, key: Key) => Duration.Duration;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.ScopedCache<Key, A, E, R>.state: State<Key, A, E>state.map: MutableHashMap.MutableHashMap<
K,
Entry<A, E>
>
(property) map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
map, key: Keykey)
return import effecteffect.const as: {
<A, B>(value: B): <E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<B, E, R>
<A, E, R, B>(
self: Effect.Effect<A, E, R>,
value: B
): Effect.Effect<B, E, R>
}
as(import ScopeScope.close(entry: Entry<A, E>entry.scope, import effecteffect.const exitVoid: Exit.Exit<void>exitVoid), true)
}
return import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false)
}),
import effecteffect.const catch_: {
<E, B, E2, R2>(
f: (e: NoInfer<E>) => Effect.Effect<B, E2, R2>
): <A, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A | B, E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect.Effect<A, E, R>,
f: (e: NoInfer<E>) => Effect.Effect<B, E2, R2>
): Effect.Effect<A | B, E2, R | R2>
}
catch_(() => import effecteffect.const succeed: <A>(
value: A
) => Effect.Effect<A>
succeed(false))
)
})
)
)
)