import * as Deferred from "./Deferred.ts"; import * as Duration from "./Duration.ts"; import type * as Effect from "./Effect.ts"; import type * as Exit from "./Exit.ts"; import * as MutableHashMap from "./MutableHashMap.ts"; import * as Option from "./Option.ts"; import type { Pipeable } from "./Pipeable.ts"; import * as Predicate from "./Predicate.ts"; import * as Scope from "./Scope.ts"; declare const TypeId = "~effect/ScopedCache"; /** * @since 4.0.0 * @category Models */ export interface ScopedCache extends Pipeable { readonly [TypeId]: typeof TypeId; state: State; readonly capacity: number; readonly lookup: (key: Key) => Effect.Effect; readonly timeToLive: (exit: Exit.Exit, key: Key) => Duration.Duration; } /** * @since 4.0.0 * @category Models */ export type State = { readonly _tag: "Open"; readonly map: MutableHashMap.MutableHashMap>; } | { readonly _tag: "Closed"; }; /** * Represents a cache entry containing a deferred value and optional expiration time. * This is used internally by the cache implementation to track cached values and their lifetimes. * * @since 4.0.0 * @category Models */ export interface Entry { expiresAt: number | undefined; readonly deferred: Deferred.Deferred; readonly scope: Scope.Closeable; } /** * @since 4.0.0 * @category Constructors */ export declare const makeWith: (options: { readonly lookup: (key: Key) => Effect.Effect; readonly capacity: number; readonly timeToLive?: ((exit: Exit.Exit, key: Key) => Duration.Input) | undefined; readonly requireServicesAt?: ServiceMode | undefined; }) => Effect.Effect : never>, never, ("lookup" extends ServiceMode ? never : R) | Scope.Scope>; /** * @since 4.0.0 * @category Constructors */ export declare const make: (options: { readonly lookup: (key: Key) => Effect.Effect; readonly capacity: number; readonly timeToLive?: Duration.Input | undefined; readonly requireServicesAt?: ServiceMode | undefined; }) => Effect.Effect : never>, never, ("lookup" extends ServiceMode ? never : R) | Scope.Scope>; /** * @since 4.0.0 * @category Combinators */ export declare const get: { /** * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect; /** * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect; }; /** * @since 4.0.0 * @category Combinators */ export declare const getOption: { /** * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect, E>; /** * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect, E>; }; /** * Retrieves the value associated with the specified key from the cache, only if * it contains a resolved successful value. * * @since 4.0.0 * @category Combinators */ export declare const getSuccess: { /** * Retrieves the value associated with the specified key from the cache, only if * it contains a resolved successful value. * * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect>; /** * Retrieves the value associated with the specified key from the cache, only if * it contains a resolved successful value. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect>; }; /** * Sets the value associated with the specified key in the cache. This will * overwrite any existing value for that key, skipping the lookup function. * * @since 4.0.0 * @category Combinators */ export declare const set: { /** * Sets the value associated with the specified key in the cache. This will * overwrite any existing value for that key, skipping the lookup function. * * @since 4.0.0 * @category Combinators */ (key: Key, value: A): (self: ScopedCache) => Effect.Effect; /** * Sets the value associated with the specified key in the cache. This will * overwrite any existing value for that key, skipping the lookup function. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key, value: A): Effect.Effect; }; /** * Checks if the cache contains an entry for the specified key. * * @since 4.0.0 * @category Combinators */ export declare const has: { /** * Checks if the cache contains an entry for the specified key. * * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect; /** * Checks if the cache contains an entry for the specified key. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect; }; /** * Invalidates the entry associated with the specified key in the cache. * * @since 4.0.0 * @category Combinators */ export declare const invalidate: { /** * Invalidates the entry associated with the specified key in the cache. * * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect; /** * Invalidates the entry associated with the specified key in the cache. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect; }; /** * Conditionally invalidates the entry associated with the specified key in the cache * if the predicate returns true for the cached value. * * @since 4.0.0 * @category Combinators */ export declare const invalidateWhen: { /** * Conditionally invalidates the entry associated with the specified key in the cache * if the predicate returns true for the cached value. * * @since 4.0.0 * @category Combinators */ (key: Key, f: Predicate.Predicate): (self: ScopedCache) => Effect.Effect; /** * Conditionally invalidates the entry associated with the specified key in the cache * if the predicate returns true for the cached value. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key, f: Predicate.Predicate): Effect.Effect; }; /** * Forces a refresh of the value associated with the specified key in the cache. * * It will always invoke the lookup function to construct a new value, * overwriting any existing value for that key. * * @since 4.0.0 * @category Combinators */ export declare const refresh: { /** * Forces a refresh of the value associated with the specified key in the cache. * * It will always invoke the lookup function to construct a new value, * overwriting any existing value for that key. * * @since 4.0.0 * @category Combinators */ (key: Key): (self: ScopedCache) => Effect.Effect; /** * Forces a refresh of the value associated with the specified key in the cache. * * It will always invoke the lookup function to construct a new value, * overwriting any existing value for that key. * * @since 4.0.0 * @category Combinators */ (self: ScopedCache, key: Key): Effect.Effect; }; /** * Invalidates all entries in the cache. * * @since 4.0.0 * @category Combinators */ export declare const invalidateAll: (self: ScopedCache) => Effect.Effect; /** * Retrieves the approximate number of entries in the cache. * * Note that expired entries are counted until they are accessed and removed. * The size reflects the current number of entries stored, not the number * of valid entries. * * @since 4.0.0 * @category Combinators */ export declare const size: (self: ScopedCache) => Effect.Effect; /** * Retrieves all active keys from the cache, automatically filtering out expired entries. * * @since 4.0.0 * @category Combinators */ export declare const keys: (self: ScopedCache) => Effect.Effect>; /** * Retrieves all successfully cached values from the cache, excluding failed * lookups and expired entries. * * @since 4.0.0 * @category Combinators */ export declare const values: (self: ScopedCache) => Effect.Effect>; /** * Retrieves all key-value pairs from the cache as an iterable. This function * only returns entries with successfully resolved values, filtering out any * failed lookups or expired entries. * * @since 4.0.0 * @category Combinators */ export declare const entries: (self: ScopedCache) => Effect.Effect>; export {}; //# sourceMappingURL=ScopedCache.d.ts.map