add cachemodule

This commit is contained in:
sbriat 2023-04-06 17:16:08 +02:00
parent 3b0f4b8c49
commit f3ca813dd6
3 changed files with 29 additions and 0 deletions

13
package-lock.json generated
View File

@ -26,6 +26,7 @@
"@nestjs/terminus": "^9.2.2", "@nestjs/terminus": "^9.2.2",
"@prisma/client": "^4.12.0", "@prisma/client": "^4.12.0",
"cache-manager": "^5.2.0", "cache-manager": "^5.2.0",
"cache-manager-ioredis-yet": "^1.1.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"ioredis": "^5.3.1", "ioredis": "^5.3.1",
@ -3413,6 +3414,18 @@
"lru-cache": "~7.18.3" "lru-cache": "~7.18.3"
} }
}, },
"node_modules/cache-manager-ioredis-yet": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cache-manager-ioredis-yet/-/cache-manager-ioredis-yet-1.1.0.tgz",
"integrity": "sha512-bGBAq8oNzzNkO2dwlYGWBxNXrz4w8FUTpe3nfUydJ6bm1ixKEcSUKYksGokQMaRgqkQjMbIHWFkvb8p+V9ZKqw==",
"dependencies": {
"cache-manager": "^5.1.0",
"ioredis": "^5.2.3"
},
"engines": {
"node": ">= 16.17.0"
}
},
"node_modules/cache-manager/node_modules/lru-cache": { "node_modules/cache-manager/node_modules/lru-cache": {
"version": "7.18.3", "version": "7.18.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz",

View File

@ -48,6 +48,7 @@
"@nestjs/terminus": "^9.2.2", "@nestjs/terminus": "^9.2.2",
"@prisma/client": "^4.12.0", "@prisma/client": "^4.12.0",
"cache-manager": "^5.2.0", "cache-manager": "^5.2.0",
"cache-manager-ioredis-yet": "^1.1.0",
"class-transformer": "^0.5.1", "class-transformer": "^0.5.1",
"class-validator": "^0.14.0", "class-validator": "^0.14.0",
"ioredis": "^5.3.1", "ioredis": "^5.3.1",

View File

@ -8,6 +8,9 @@ import { MatchProfile } from './mappers/match.profile';
import { AdRepository } from './adapters/secondaries/ad.repository'; import { AdRepository } from './adapters/secondaries/ad.repository';
import { MatchUseCase } from './domain/usecases/match.usecase'; import { MatchUseCase } from './domain/usecases/match.usecase';
import { Messager } from './adapters/secondaries/messager'; import { Messager } from './adapters/secondaries/messager';
import { CacheModule } from '@nestjs/cache-manager';
import { RedisClientOptions } from '@liaoliaots/nestjs-redis';
import { redisStore } from 'cache-manager-ioredis-yet';
@Module({ @Module({
imports: [ imports: [
@ -27,6 +30,18 @@ import { Messager } from './adapters/secondaries/messager';
}), }),
inject: [ConfigService], inject: [ConfigService],
}), }),
CacheModule.registerAsync<RedisClientOptions>({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
store: await redisStore({
host: configService.get<string>('REDIS_HOST'),
port: configService.get<number>('REDIS_PORT'),
password: configService.get<string>('REDIS_PASSWORD'),
ttl: configService.get<number>('CACHE_TTL'),
}),
}),
inject: [ConfigService],
}),
], ],
controllers: [MatcherController], controllers: [MatcherController],
providers: [MatchProfile, AdRepository, Messager, MatchUseCase], providers: [MatchProfile, AdRepository, Messager, MatchUseCase],