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";
import { Cache } from "@daiso-tech/core/cache";
import { Kysely, SqliteDialect } from "kysely";
const database = new Sqlite("local.db");
const serde = new Serde(new SuperJsonSerdeAdapter());
const cacheAdapter = new KyselyCacheAdapter({
kysely: new Kysely({
dialect: new SqliteDialect({
database,
}),
}),
serde,
});
// You need initialize the adapter once before using it.
await cacheAdapter.init();
const cache = new Cache({
adapter: cacheAdapter,
});
The decrement method decrements the given key with given value.
An error will thrown if the value is not a number.
If not defined then it will be defaulted to 1.
Returns true if the key where decremented otherwise false will be returned.
The decrementOrFail method decrements the given key with given value.
An error will thrown if the value is not a number or if the key is not found.
Optionalvalue: Extract<TType, number>If not defined then it will be defaulted to 1.
Retrieves a cached value with a default fallback.
The cache key to retrieve
Default value to return if key is not found. Can be a static value, sync function, or async function.
The cached value, or the default value if the key is not found
The getOrAdd method retrieves the value for the given key if it exists,
otherwise adds the valueToAdd to the cache and returns it.
The cached value if the key exists, or the newly added value.
The increment method increments the given key with given value.
An error will thrown if the value is not a number.
If not defined then it will be defaulted to 1.
Returns true if the key where incremented otherwise false will be returned.
The incrementOrFail method increments the given key with given value.
An error will thrown if the value is not a number or if the key is not found.
Optionalvalue: Extract<TType, number>If not defined then it will be defaulted to 1.
IMPORT_PATH:
"@daiso-tech/core/cache"