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.

60 lines (59 loc) 2.51 kB
/** * @module Cache */ import { type ICacheData, type ICacheInsert, type ICacheUpdate, type IDatabaseCacheAdapter } from "../../../../cache/contracts/_module-exports.js"; import { type TimeSpan, type IInitizable, type IDeinitizable, type IPrunable, type ISqliteDatabase } from "../../../../utilities/_module-exports.js"; import type { ISerde } from "../../../../serde/contracts/_module-exports.js"; /** * * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"` * @group Adapters */ export type SqliteCacheAdapterSettings = { database: ISqliteDatabase; tableName?: string; serde: ISerde<string>; expiredKeysRemovalInterval?: TimeSpan; shouldRemoveExpiredKeys?: boolean; }; /** * To utilize the `SqliteCacheAdapter`, you must install the `"better-sqlite3"` package and supply a {@link ISerde | `ISerde<string>`}, with adapter like {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}. * * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"` * @group Adapters */ export declare class SqliteCacheAdapter<TType = unknown> implements IDatabaseCacheAdapter<TType>, IInitizable, IDeinitizable, IPrunable { private readonly adapter; /** * @example * ```ts * import { SqliteCacheAdapter } from "@daiso-tech/core/cache/adapters"; * import { Serde } from "@daiso-tech/core/serde"; * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters" * import Sqlite from "better-sqlite3"; * * const database = new Sqlite("local.db"); * const serde = new Serde(new SuperJsonSerdeAdapter()); * const cacheAdapter = new SqliteCacheAdapter({ * database, * serde, * }); * // You need initialize the adapter once before using it. * await cacheAdapter.init(); * ``` */ constructor(settings: SqliteCacheAdapterSettings); removeAllExpired(): Promise<void>; deInit(): Promise<void>; init(): Promise<void>; insert(data: ICacheInsert<TType>): Promise<void>; upsert(data: ICacheInsert<TType>): Promise<ICacheData<TType> | null>; find(key: string): Promise<ICacheData<TType> | null>; updateExpired(data: ICacheInsert<TType>): Promise<number>; updateUnexpired(data: ICacheUpdate<TType>): Promise<number>; incrementUnexpired(data: ICacheUpdate<number>): Promise<number>; removeUnexpiredMany(keys: string[]): Promise<number>; removeExpiredMany(keys: string[]): Promise<number>; removeAll(): Promise<void>; removeByKeyPrefix(prefix: string): Promise<void>; }