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.

74 lines (73 loc) 2.26 kB
/** * @module Cache */ import { type ICacheData, type ICacheInsert, type ICacheUpdate, type IDatabaseCacheAdapter } from "../../../../cache/contracts/_module-exports.js"; import type { ISerde } from "../../../../serde/contracts/_module-exports.js"; import type { IDeinitizable, IInitizable, IPrunable } from "../../../../utilities/_module-exports.js"; import { TimeSpan } from "../../../../utilities/_module-exports.js"; import type { Kysely } from "kysely"; /** * @internal */ type KyselyCacheTable = { key: string; value: string; expiration: number | null; }; /** * @internal */ type KyselyTables = { cache: KyselyCacheTable; }; /** * @internal */ type KyselySettings = { database: Kysely<KyselyTables>; serde: ISerde<string>; /** * @default {false} */ disableTransaction?: boolean; /** * @default * ```ts * TimeSpan.fromMinutes(1) * ``` */ expiredKeysRemovalInterval?: TimeSpan; /** * @default {true} */ shouldRemoveExpiredKeys?: boolean; }; /** * @internal */ export declare class KyselyCacheAdapter<TType = unknown> implements IDatabaseCacheAdapter<TType>, IInitizable, IDeinitizable, IPrunable { private static filterUnexpiredKeys; private static filterExpiredKeys; private readonly serde; private readonly database; private readonly shouldRemoveExpiredKeys; private readonly expiredKeysRemovalInterval; private timeoutId; private readonly disableTransaction; constructor(settings: KyselySettings); removeAllExpired(): Promise<void>; init(): Promise<void>; deInit(): Promise<void>; find(key: string): Promise<ICacheData<TType> | null>; insert(data: ICacheInsert<TType>): Promise<void>; private transaction; upsert(data: ICacheInsert<TType>): Promise<ICacheData<TType> | null>; updateExpired(data: ICacheInsert<TType>): Promise<number>; updateUnexpired(data: ICacheUpdate<TType>): Promise<number>; incrementUnexpired(data: ICacheUpdate<number>): Promise<number>; removeExpiredMany(keys: string[]): Promise<number>; removeUnexpiredMany(keys: string[]): Promise<number>; removeAll(): Promise<void>; removeByKeyPrefix(prefix: string): Promise<void>; } export {};