Class MongodbCacheAdapter<TType>

tis kl 9 To utilize the MongodbCacheAdapter, you must install the "mongodb" package and supply a string serde, such as SuperJsonSerde.

import { MongodbCacheAdapter, SuperJsonSerde } from "@daiso-tech/core";
import { MongoClient } from "mongodb";

const client = new MongoClient("YOUR_MONGODB_CONNECTION_STRING");
const database = client.db("database");
const cacheCollection = database.collection("cache");
const serde = new SuperJsonSerde();
const cacheAdapter = new MongodbCacheAdapter(cacheCollection, {
serde,
rootGroup: "@global"
});

(async () => {
// You only need to call it once before using the adapter.
await cacheAdapter.init();
await cacheAdapter.add("a", 1);
})();

Type Parameters

  • TType

Implements

Constructors

Methods

  • The put method replaces a key if the key exists including the ttl value or adds key that do not exists with a given ttl. Returns true if the key where replaced otherwise false is returned. You must provide a ttl value. If null is passed, the item will not expire.

    Parameters

    Returns Promise<boolean>