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.

62 lines (61 loc) 2.56 kB
/** * @module Cache */ import type { ICacheData, ICacheInsert, ICacheUpdate, IDatabaseCacheAdapter } from "../../../../cache/contracts/_module-exports.js"; import type { TimeSpan, IDeinitizable, IInitizable, IPrunable } from "../../../../utilities/_module-exports.js"; import type { ISerde } from "../../../../serde/contracts/_module-exports.js"; import type { Client } from "@libsql/client"; /** * * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"` * @group Adapters */ export type LibsqlCacheAdapterSettings = { database: Client; tableName?: string; serde: ISerde<string>; disableTransaction?: boolean; expiredKeysRemovalInterval?: TimeSpan; shouldRemoveExpiredKeys?: boolean; }; /** * To utilize the `LibsqlCacheAdapter`, you must install the `"@libsql/client"` package and supply a {@link ISerde | `ISerde<string>`}, with an adapter like {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}. * * IMPORT_PATH: `"@daiso-tech/core/cache/adapters"` * @group Adapters */ export declare class LibsqlCacheAdapter<TType = unknown> implements IDatabaseCacheAdapter<TType>, IInitizable, IDeinitizable, IPrunable { private readonly adapter; /*** * @example * ```ts * import { LibsqlCacheAdapter } from "@daiso-tech/core/cache/adapters"; * import { Serde } from "@daiso-tech/core/serde"; * import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/adapters"; * import { createClient } from "@libsql/client"; * * const database = createClient({ url: "file:local.db" }); * const serde = new Serde(new SuperJsonSerdeAdapter()); * const cacheAdapter = new LibsqlCacheAdapter({ * database, * serde, * }); * // You need initialize the adapter once before using it. * await cacheAdapter.init(); * ``` */ constructor(settings: LibsqlCacheAdapterSettings); 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>; }