UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

38 lines (37 loc) 1.78 kB
/** * @module Cache */ import { type ICacheAdapter } from "../../../../cache/contracts/_module.js"; import { type IReadableContext } from "../../../../execution-context/contracts/_module.js"; import { type TimeSpan } from "../../../../time-span/implementations/_module.js"; /** * The `MemoryCacheAdapter` is used for easily faking{@link ICache | `ICache`} for testing. * * IMPORT_PATH: `"@daiso-tech/core/cache/memory-cache-adapter"` * @group Adapters */ export declare class MemoryCacheAdapter<TType = unknown> implements ICacheAdapter<TType> { private readonly map; private readonly timeoutMap; /** * You can provide an optional {@link Map | `Map`}, that will be used for storing the data. * @example * ```ts * import { MemoryCacheAdapter } from "@daiso-tech/core/cache/memory-cache-adapter"; * * const map = new Map<any, any>(); * const cacheAdapter = new MemoryCacheAdapter(map); * ``` */ constructor(map?: Map<string, unknown>); get(_context: IReadableContext, key: string): Promise<TType | null>; getAndRemove(context: IReadableContext, key: string): Promise<TType | null>; add(_context: IReadableContext, key: string, value: TType, ttl: TimeSpan | null): Promise<boolean>; put(context: IReadableContext, key: string, value: TType, ttl: TimeSpan | null): Promise<boolean>; update(_context: IReadableContext, key: string, value: TType): Promise<boolean>; increment(_context: IReadableContext, key: string, value: number): Promise<boolean>; remove(key: string): Promise<boolean>; removeMany(_context: IReadableContext, keys: Array<string>): Promise<boolean>; removeAll(): Promise<void>; removeByKeyPrefix(_context: IReadableContext, prefix: string): Promise<void>; }