Skip to content

Commit

Permalink
[ADD] cache implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
marluanespiritusanto committed Aug 25, 2021
1 parent 064e4c7 commit 4445a8a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
39 changes: 33 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.0.9",
"cache-manager": "^3.4.4",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"compression": "^1.7.4",
Expand Down
11 changes: 9 additions & 2 deletions src/modules/contributors/contributors.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TransformInterceptor } from '@common/interceptors';
import {
CacheInterceptor,
Controller,
Get,
Param,
Expand All @@ -17,14 +18,20 @@ export class ContributorsController {
constructor(private readonly contributorService: ContributorsService) {}

@Get(':rnc/info/basic')
@UseInterceptors(new TransformInterceptor(ResponseContributorDto))
@UseInterceptors(
new TransformInterceptor(ResponseContributorDto),
CacheInterceptor,
)
@UseGuards(RncValidatorGuard)
getContributors(@Param('rnc') rnc: string) {
return this.contributorService.getContributors(rnc);
}

@Get('search')
@UseInterceptors(new TransformInterceptor(ResponseContributorDto))
@UseInterceptors(
new TransformInterceptor(ResponseContributorDto),
CacheInterceptor,
)
getContributorByName(@Query('name') name: string) {
return this.contributorService.getContributorByName(name);
}
Expand Down
19 changes: 16 additions & 3 deletions src/modules/contributors/contributors.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { Module } from '@nestjs/common';
import { CacheInterceptor, CacheModule, Module } from '@nestjs/common';

import { ContributorsController } from './contributors.controller';
import { ContributorsService } from './contributors.service';
import { SoapModule } from '@modules/soap/soap.module';
import { APP_INTERCEPTOR } from '@nestjs/core';

@Module({
imports: [SoapModule],
imports: [
SoapModule,
CacheModule.register({
ttl: 3600,
max: 100,
}),
],
controllers: [ContributorsController],
providers: [ContributorsService],
providers: [
ContributorsService,
{
provide: APP_INTERCEPTOR,
useClass: CacheInterceptor,
},
],
})
export class ContributorsModule {}
6 changes: 3 additions & 3 deletions src/modules/contributors/contributors.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export class ContributorsService {

return new Promise((res, rej) => {
const args = {
value: '', //name,
value: name,
patronBusqueda: SEARCH_BY_NAME_CODE,
inicioFilas: 1, //SEARCH_FROM,
filaFilas: 10000, //ELEMENTS_PER_PAGE,
inicioFilas: SEARCH_FROM,
filaFilas: ELEMENTS_PER_PAGE,
IMEI: '',
};

Expand Down

0 comments on commit 4445a8a

Please sign in to comment.