-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from VentionCapstone/feat/117_add-cache
Feat/117 add cache
- Loading branch information
Showing
5 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Injectable, OnApplicationBootstrap } from '@nestjs/common'; | ||
import { AccommodationService } from './accommodation.service'; | ||
import { OrderAndFilterDto } from './dto/orderAndFilter.dto'; | ||
|
||
const { CACHING_PAGES, CACHING_PAGES_LIMIT } = process.env; | ||
const CachingPages = parseInt(CACHING_PAGES!); | ||
const CachingPagesLimit = parseInt(CACHING_PAGES_LIMIT!); | ||
|
||
@Injectable() | ||
export class CacheService implements OnApplicationBootstrap { | ||
constructor(private accommodationService: AccommodationService) {} | ||
|
||
async onApplicationBootstrap() { | ||
await this.cacheMainPages(); | ||
} | ||
|
||
async cacheMainPages() { | ||
for (let page = 1; page <= CachingPages; page++) { | ||
const options: OrderAndFilterDto = { page, limit: CachingPagesLimit }; | ||
await this.accommodationService.getAllAccommodations(options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { CacheModule } from '@nestjs/cache-manager'; | ||
import { Module } from '@nestjs/common'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
import { CacheService } from './accommodation.cache.service'; | ||
import { AccommodationController } from './accommodation.controller'; | ||
import { AccommodationService } from './accommodation.service'; | ||
|
||
const { CACHE_TIMEOUT } = process.env; | ||
const CacheTimeout = parseInt(CACHE_TIMEOUT!); | ||
|
||
@Module({ | ||
imports: [PrismaModule, JwtModule.register({}), HttpModule], | ||
imports: [ | ||
PrismaModule, | ||
JwtModule.register({}), | ||
HttpModule, | ||
CacheModule.register({ ttl: CacheTimeout }), | ||
], | ||
controllers: [AccommodationController], | ||
providers: [AccommodationService], | ||
providers: [AccommodationService, CacheService], | ||
}) | ||
export class AccommodationModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters