Type Alias IGroupableCache<TType>

IGroupableCache<TType>: ICache<TType> & {
    withGroup(group: OneOrMore<string>): ICache<TType>;
}

The IGroupableCache contract defines a way for storing data as key-value pairs independent of data storage. It commes with one extra method which is useful for multitennat applications compared to ICache.

Type Parameters

  • TType = unknown

Type declaration

  • withGroup:function
    • The withGroup method returns a new ICache instance that groups keys together. Only keys in the group can be updated, removed, or retrieved, leaving keys outside the group unaffected. This useful for multitennat applications.

      Parameters

      Returns ICache<TType>

      import { type ICache } from "@daiso-tech/core";

      async function main(cache: ICache): Promise<void> {
      const cacheA = cache.withGroup("a");
      await cacheA.add("a", 1);

      const cacheB = cache.withGroup("b");
      await cacheB.add("b", 2);

      // Will print { a: 1, b: null }
      console.log(await cacheA.getMany(["a", "b"]));
      }