import { KyselyCacheAdapter } from "@daiso-tech/core/cache/kysely-cache-adapter";
import { Serde } from "@daiso-tech/core/serde";
import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/super-json-serde-adapter"
import Sqlite from "better-sqlite3";
const serde = new Serde(new SuperJsonSerdeAdapter());
const cacheAdapter = new KyselyCacheAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database: new Sqlite("local.db"),
}),
}),
serde,
});
// You need initialize the adapter once before using it.
await cacheAdapter.init();
The find method returns the the key data which includs ICacheData.value and ICacheData.expiration.
The incrementUnexpired should always throw an error if the existing item is not a number type.
The insert method inserts the given cache data.
The removeExpiredMany method updates a expired key.
The removeExpiredMany method updates a unexpired key.
The upsert method inserts a key and if the key already exists then key will be updated with new data.value and data.expiration.
The method always returns the old cache data if it exists otherwise null will be returned.
To utilize the
KyselyCacheAdapter, you must install the"kysely"package and configure aKyselyclass instance. The adapter have been tested withsqlite,postgresandmysqldatabases.IMPORT_PATH:
"@daiso-tech/core/cache/kysely-cache-adapter"