mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:12:40 +00:00
use basic cache
This commit is contained in:
@@ -35,6 +35,27 @@ import { MatchMapper } from './match.mapper';
|
||||
import { OutputDateTimeTransformer } from './infrastructure/output-datetime-transformer';
|
||||
import { MatchingRepository } from './infrastructure/matching.repository';
|
||||
import { MatchingMapper } from './matching.mapper';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { RedisClientOptions } from '@liaoliaots/nestjs-redis';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { redisStore } from 'cache-manager-ioredis-yet';
|
||||
|
||||
const imports = [
|
||||
CqrsModule,
|
||||
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('CACHE_TTL'),
|
||||
}),
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
GeographyModule,
|
||||
];
|
||||
|
||||
const grpcControllers = [MatchGrpcController];
|
||||
|
||||
@@ -106,7 +127,7 @@ const adapters: Provider[] = [
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule, GeographyModule],
|
||||
imports,
|
||||
controllers: [...grpcControllers],
|
||||
providers: [
|
||||
...messageHandlers,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Inject, UsePipes } from '@nestjs/common';
|
||||
import { Controller, Inject, UseInterceptors, UsePipes } from '@nestjs/common';
|
||||
import { GrpcMethod, RpcException } from '@nestjs/microservices';
|
||||
import { RpcValidationPipe } from '@mobicoop/ddd-library';
|
||||
import { RpcExceptionCode } from '@mobicoop/ddd-library';
|
||||
@@ -11,6 +11,7 @@ import { AD_ROUTE_PROVIDER } from '@modules/ad/ad.di-tokens';
|
||||
import { RouteProviderPort } from '@modules/ad/core/application/ports/route-provider.port';
|
||||
import { MatchMapper } from '@modules/ad/match.mapper';
|
||||
import { MatchingResult } from '@modules/ad/core/application/queries/match/match.query-handler';
|
||||
import { CacheInterceptor, CacheKey } from '@nestjs/cache-manager';
|
||||
|
||||
@UsePipes(
|
||||
new RpcValidationPipe({
|
||||
@@ -27,6 +28,8 @@ export class MatchGrpcController {
|
||||
private readonly matchMapper: MatchMapper,
|
||||
) {}
|
||||
|
||||
@CacheKey('MatcherServiceMatch')
|
||||
@UseInterceptors(CacheInterceptor)
|
||||
@GrpcMethod('MatcherService', 'Match')
|
||||
async match(data: MatchRequestDto): Promise<MatchingPaginatedResponseDto> {
|
||||
try {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { MatchRequestDto } from '@modules/ad/interface/grpc-controllers/dtos/mat
|
||||
import { WaypointDto } from '@modules/ad/interface/grpc-controllers/dtos/waypoint.dto';
|
||||
import { MatchGrpcController } from '@modules/ad/interface/grpc-controllers/match.grpc-controller';
|
||||
import { MatchMapper } from '@modules/ad/match.mapper';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { QueryBus } from '@nestjs/cqrs';
|
||||
import { RpcException } from '@nestjs/microservices';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
@@ -316,6 +317,10 @@ describe('Match Grpc Controller', () => {
|
||||
provide: MatchMapper,
|
||||
useValue: mockMatchMapper,
|
||||
},
|
||||
{
|
||||
provide: CACHE_MANAGER,
|
||||
useValue: {},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user