Class CacheFactory<TAdapters>

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

Type Parameters

  • TAdapters extends string = string

Implements

Constructors

Methods

Constructors

  • Type Parameters

    • TAdapters extends string = string

    Parameters

    Returns CacheFactory<TAdapters>

    import { CacheFactory } from "@daiso-tech/core/cache/implementations/derivables";
    import { MemoryCacheAdapter, RedisCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
    import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
    import Redis from "ioredis"

    const serde = new Serde(new SuperJsonSerdeAdapter());
    const cacheFactory = new CacheFactory({
    serde,
    adapters: {
    memory: new MemoryCacheAdapter({
    rootGroup: "@global"
    }),
    redis: new RedisCacheAdapter({
    client: new Redis("YOUR_REDIS_CONNECTION"),
    serde,
    rootGroup: "@global"
    }),
    },
    defaultAdapter: "memory",
    });

Methods

  • Type Parameters

    • TType = unknown

    Parameters

    Returns IGroupableCache<TType>

    import { CacheFactory } from "@daiso-tech/core/cache/implementations/derivables";
    import { MemoryCacheAdapter, RedisCacheAdapter } from "@daiso-tech/core/cache/implementations/adapters";
    import { Serde } from "@daiso-tech/core/serde/implementations/derivables";
    import { SuperJsonSerdeAdapter } from "@daiso-tech/core/serde/implementations/adapters";
    import Redis from "ioredis"

    const serde = new Serde(new SuperJsonSerdeAdapter());
    const cacheFactory = new CacheFactory({
    serde,
    adapters: {
    memory: new MemoryCacheAdapter({
    rootGroup: "@global"
    }),
    redis: new RedisCacheAdapter({
    client: new Redis("YOUR_REDIS_CONNECTION"),
    serde,
    rootGroup: "@global"
    }),
    },
    defaultAdapter: "memory",
    eventBus,
    });

    // Will add key to cache using the default adapter which is MemoryCacheAdapter
    await cacheFactory.use().add("a", 1);

    // Will add key to cache using the redis adapter which is RedisCacheAdapter
    await cacheFactory.use("redis").add("a", 1);