dashpresshq/dashpress

View on GitHub
src/backend/lib/cache/index.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { configApiService, ConfigKeys } from "../config/config.service";
import { AbstractCacheService } from "./AbstractCacheService";
import { MemoryCacheAdaptor } from "./MemoryCacheAdaptor";
import { RedisCacheAdaptor } from "./RedisCacheAdaptor";
import { CacheAdaptorTypes } from "./types";

export { AbstractCacheService };

export function createCacheService(): AbstractCacheService {
  const configBag: Record<CacheAdaptorTypes, AbstractCacheService> = {
    [CacheAdaptorTypes.Memory]: new MemoryCacheAdaptor(configApiService),
    [CacheAdaptorTypes.Redis]: new RedisCacheAdaptor(configApiService),
  };

  return configBag[
    configApiService.getConfigValue<CacheAdaptorTypes>(ConfigKeys.CACHE_ADAPTOR)
  ];
}