Class Cache<TType>

IMPORT_PATH: "@daiso-tech/core/cache"

Type Parameters

  • TType = unknown

Implements

Constructors

  • Type Parameters

    • TType = unknown

    Parameters

    Returns Cache<TType>

    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,
    });

Accessors

Methods

  • The decrement method decrements the given key with given value. An error will thrown if the value is not a number.

    Parameters

    • key: string
    • value: Extract<TType, number> = ...

      If not defined then it will be defaulted to 1.

    Returns ITask<boolean>

    Returns true if the key where decremented otherwise false will be returned.

    TypeError

  • 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.

    Parameters

    • key: string
    • Optionalvalue: Extract<TType, number>

      If not defined then it will be defaulted to 1.

    Returns ITask<void>

    TypeError

  • The increment method increments the given key with given value. An error will thrown if the value is not a number.

    Parameters

    • key: string
    • value: Extract<TType, number> = ...

      If not defined then it will be defaulted to 1.

    Returns ITask<boolean>

    Returns true if the key where incremented otherwise false will be returned.

    TypeError

  • 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.

    Parameters

    • key: string
    • Optionalvalue: Extract<TType, number>

      If not defined then it will be defaulted to 1.

    Returns ITask<void>

    TypeError

  • The removeMany method removes many keys.

    Parameters

    • keys: Iterable<string, any, any>

      The param items can be a string or an Iterable of strings. If the param items are an Iterable, it will be joined into a single string. Think of an Iterable as representing a path.

    Returns ITask<boolean>

    Returns true if one of the keys where deleted otherwise false is returned.