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",
});
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);
IMPORT_PATH:
"@daiso-tech/core/cache/implementations/derivables"