2021-04-13 21:53:58 +02:00
|
|
|
import { CacheModule, Module } from '@nestjs/common';
|
|
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
|
import * as redisStore from 'cache-manager-redis-store';
|
|
|
|
|
2021-04-18 19:06:54 +02:00
|
|
|
import { ConfigurationService } from '../../services/configuration.service';
|
2021-04-13 21:53:58 +02:00
|
|
|
import { RedisCacheService } from './redis-cache.service';
|
|
|
|
|
|
|
|
@Module({
|
|
|
|
imports: [
|
|
|
|
CacheModule.registerAsync({
|
|
|
|
imports: [ConfigModule],
|
|
|
|
inject: [ConfigService],
|
2021-04-18 19:06:54 +02:00
|
|
|
useFactory: async (configurationService: ConfigurationService) => ({
|
|
|
|
host: configurationService.get('REDIS_HOST'),
|
|
|
|
max: configurationService.get('MAX_ITEM_IN_CACHE'),
|
|
|
|
port: configurationService.get('REDIS_PORT'),
|
2021-04-13 21:53:58 +02:00
|
|
|
store: redisStore,
|
2021-04-18 19:06:54 +02:00
|
|
|
ttl: configurationService.get('CACHE_TTL')
|
2021-04-13 21:53:58 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
],
|
2021-04-18 19:06:54 +02:00
|
|
|
providers: [ConfigurationService, RedisCacheService],
|
2021-04-13 21:53:58 +02:00
|
|
|
exports: [RedisCacheService]
|
|
|
|
})
|
|
|
|
export class RedisCacheModule {}
|