/** * @since 1.0.0 */ import type * as Either from "@effect/data/Either" import type * as Option from "@effect/data/Option" import type * as Effect from "@effect/io/Effect" import type * as Ref from "@effect/io/Ref" import * as internal from "@effect/query/internal_effect_untraced/cache" import type * as Request from "@effect/query/Request" /** * @since 1.0.0 * @category symbols */ export const CacheTypeId: unique symbol = internal.CacheTypeId /** * @since 1.0.0 * @category symbols */ export type CacheTypeId = typeof CacheTypeId /** * A `Cache` maintains an internal state with a mapping from requests to `Ref`s * that will contain the result of those requests when they are executed. This * is used internally by the library to provide deduplication and caching of * requests. * * @since 1.0.0 * @category models */ export interface Cache extends Cache.Proto { /** * Looks up a request in the cache, failing with the unit value if the request * is not in the cache, succeeding with `Ref(None)` if the request is in the * cache but has not been executed yet, or `Ref(Some(value))` if the request * has been executed. */ get(request: Request.Request): Effect.Effect>>> /** * Looks up a request in the cache. If the request is not in the cache returns * a `Left` with a `Ref` that can be set with a `Some` to complete the * request. If the request is in the cache returns a `Right` with a `Ref` that * either contains `Some` with a result if the request has been executed or * `None` if the request has not been executed yet. */ lookup( request: Request.Request ): Effect.Effect< never, never, Either.Either< Ref.Ref>>, Ref.Ref>> > > /** * Inserts a request and a `Ref` that will contain the result of the request * when it is executed into the cache. */ set( request: Request.Request, result: Ref.Ref>> ): Effect.Effect /** * Removes a request from the cache. */ remove(request: Request.Request): Effect.Effect } /** * @since 1.0.0 */ export declare namespace Cache { /** * @since 1.0.0 * @category models */ export interface Proto { readonly [CacheTypeId]: CacheTypeId } } /** * Constructs an empty cache. * * @since 1.0.0 * @category constructors */ export const empty: () => Effect.Effect = internal.empty /** * Looks up a request in the cache, failing with the unit value if the request * is not in the cache, succeeding with `Ref(None)` if the request is in the * cache but has not been executed yet, or `Ref(Some(value))` if the request * has been executed. * * @since 1.0.0 * @category elements */ export const get: { ( request: Request.Request ): (self: Cache) => Effect.Effect>>> ( self: Cache, request: Request.Request ): Effect.Effect>>> } = internal.get /** * Looks up a request in the cache. If the request is not in the cache returns * a `Left` with a `Ref` that can be set with a `Some` to complete the * request. If the request is in the cache returns a `Right` with a `Ref` that * either contains `Some` with a result if the request has been executed or * `None` if the request has not been executed yet. * * @since 1.0.0 * @category elements */ export const lookup: { ( request: Request.Request ): ( self: Cache ) => Effect.Effect< never, never, Either.Either>>, Ref.Ref>>> > ( self: Cache, request: Request.Request ): Effect.Effect< never, never, Either.Either>>, Ref.Ref>>> > } = internal.lookup /** * Inserts a request and a `Ref` that will contain the result of the request * when it is executed into the cache. * * @since 1.0.0 * @category mutations */ export const set: { ( request: Request.Request, result: Ref.Ref>> ): (self: Cache) => Effect.Effect ( self: Cache, request: Request.Request, result: Ref.Ref>> ): Effect.Effect } = internal.set /** * Removes a request from the cache. * * @since 1.0.0 * @category mutations */ export const remove: { (request: Request.Request): (self: Cache) => Effect.Effect (self: Cache, request: Request.Request): Effect.Effect } = internal.remove