mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 01:41:24 -06:00
29 lines
839 B
TypeScript
29 lines
839 B
TypeScript
import { ICache } from '@api/abstract/abstract.cache';
|
|
import { CacheConf, ConfigService } from '@config/env.config';
|
|
import { Logger } from '@config/logger.config';
|
|
|
|
import { LocalCache } from './localcache';
|
|
import { RedisCache } from './rediscache';
|
|
|
|
const logger = new Logger('Redis');
|
|
|
|
export class CacheEngine {
|
|
private engine: ICache;
|
|
|
|
constructor(private readonly configService: ConfigService, module: string) {
|
|
const cacheConf = configService.get<CacheConf>('CACHE');
|
|
|
|
if (cacheConf?.REDIS?.ENABLED && cacheConf?.REDIS?.URI !== '') {
|
|
this.engine = new RedisCache(configService, module);
|
|
} else if (cacheConf?.LOCAL?.ENABLED) {
|
|
this.engine = new LocalCache(configService, module);
|
|
}
|
|
|
|
logger.info(`RedisCache initialized for ${module}`);
|
|
}
|
|
|
|
public getEngine() {
|
|
return this.engine;
|
|
}
|
|
}
|