import { type SyncOrAsync, type Result } from '@conduit-client/utils'; import type { CacheQuery } from './cache-query'; import type { DeepReadonly, NamedService, ServiceDescriptor } from '@conduit-client/utils'; import type { CacheEntry, Key, Cache } from '@conduit-client/service-cache/v1'; import type { CacheUpdate } from './cache-update'; /** * CacheInclusionPolicy is an interface for accessing the cache * and synchronizing the cache data with another external cache. * * https://en.wikipedia.org/wiki/Cache_inclusion_policy */ export declare abstract class CacheInclusionPolicyService { /** * Reads data out of a cache applying a multilevel cache inclusion policy to the results. * * @param {Cache} l1 The cache to use for L1 cache reads. * @param {(cache: Cache) => SyncOrAsync} readFromL1 A function for reading the data from L1. * The readFromL1 function returns a boolean indicating whether the completed read operation * was successful. * @returns {SyncOrAsync} */ abstract read>(options: { l1: Cache; readFromL1: (l1: Cache) => SyncOrAsync; }): SyncOrAsync; /** * Write data out to a cache applying a multilevel cache inclusion policy to the writes. * * @param {Cache} l1 The cache to use for L1 cache writes. * @param {(l1: Cache) => SyncOrAsync} writeToL1 A function for writing the data to L1. * @returns {SyncOrAsync} */ abstract write>(options: { l1: Cache; writeToL1: (l1: Cache) => SyncOrAsync; }): SyncOrAsync; /** * Finds cache entries that match the given query. * Returns an async generator that yields `[key, entry]`. */ abstract find(query: CacheQuery): AsyncGenerator<[key: Key, value: DeepReadonly>], void, unknown>; /** * Finds and modifies cache entries that match the given query. * Extends `find(query)` and returns an async generator of modified keys. */ abstract findAndModify(query: CacheQuery, cacheUpdate: CacheUpdate): AsyncGenerator; } export type NamedCacheInclusionPolicyService = NamedService; export type CacheInclusionPolicyServiceDescriptor = ServiceDescriptor;