/** * @module Cache */ import { type ICacheAdapter } from "../../../../cache/contracts/_module.js"; import { type ILockFactory } from "../../../../lock/contracts/_module.js"; import { type PluginFn } from "../../../../middleware/contracts/_module.js"; /** * Cache adapter methods that can be protected by a write lock. * * Only the mutable methods that modify cache state are eligible for write-lock * protection. * * IMPORT_PATH: `"@daiso-tech/core/cache/plugins"` * @group Plugins */ export type WithCacheWriteLockMethods = keyof Pick; /** * Settings for the {@link withCacheWriteLock} plugin. * * IMPORT_PATH: `"@daiso-tech/core/cache/plugins"` * @group Plugins */ export type WithCacheWriteLockSettings = { /** * A factory that creates named locks. * Each lock is keyed by the cache key to ensure concurrent writes * to the same cache entry are serialised while writes to different * entries can proceed in parallel. */ lockFactory: ILockFactory; /** * The subset of mutating methods to protect with a write lock. * When omitted, all mutating methods are protected. * * @default * ```ts * ["getAndRemove", "add", "put", "update", "increment", "removeMany", "getOrAdd"] * ``` */ onlyMethods?: Array; }; /** * Creates a plugin that acquires a distributed lock before executing mutating * cache operations. * * This plugin wraps write operations (`add`, `put`, `update`, `increment`, * `getAndRemove`, `removeMany`) with a lock acquired via {@link ILockFactory}. * The lock key is derived from the cache key, ensuring that concurrent writes * to the same cache entry are serialised. By default all mutating methods are * protected; use `onlyMethods` to restrict which operations are locked. * * @param settings - Configuration for the write-lock behaviour. * @param settings.lockFactory - A factory that creates named locks. * @param settings.onlyMethods - The subset of methods to protect with a write * lock. Defaults to all mutating methods. * @returns A middleware plugin that wraps an `ICacheAdapter`. * * IMPORT_PATH: `"@daiso-tech/core/cache/plugins"` * @group Plugins */ export declare function withCacheWriteLock(settings: WithCacheWriteLockSettings): PluginFn;