Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LBAC-1845 Paramétrage limitant du cache axios #920

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@types/nodemailer-html-to-text": "^3.1.1",
"aws-sdk": "^2.1466.0",
"axios": "^1.5.1",
"axios-cache-interceptor": "^0.10.7",
"axios-cache-interceptor": "^1.3.2",
"basic-ftp": "^5.0.3",
"boom": "^7.3.0",
"bunyan": "^1.8.15",
Expand Down
13 changes: 7 additions & 6 deletions server/src/common/apis/client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// import http from "http"
// import https from "https"

import axios, { AxiosRequestConfig } from "axios"
import { setupCache } from "axios-cache-interceptor"
import { buildMemoryStorage, setupCache } from "axios-cache-interceptor"

const CLEANUP_INTERVAL = 1000 * 60 * 10 // 10 minutes
const MAX_ENTRIES = 200
const CLONE_DATA = false

const getApiClient = (options: AxiosRequestConfig, { cache }: { cache: boolean } = { cache: true }) => {
const axiosInstance = axios.create({
timeout: 5000,
// httpAgent: new http.Agent({ keepAlive: true }),
// httpsAgent: new https.Agent({ keepAlive: true }),
...options,
})

return cache
? setupCache(axiosInstance, {
storage: buildMemoryStorage(CLONE_DATA, CLEANUP_INTERVAL, MAX_ENTRIES),
ttl: 1000 * 60 * 10, // 10 Minutes
})
: axiosInstance
Expand Down
22 changes: 12 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5431,14 +5431,16 @@ __metadata:
languageName: node
linkType: hard

"axios-cache-interceptor@npm:^0.10.7":
version: 0.10.7
resolution: "axios-cache-interceptor@npm:0.10.7"
"axios-cache-interceptor@npm:^1.3.2":
version: 1.3.2
resolution: "axios-cache-interceptor@npm:1.3.2"
dependencies:
cache-parser: ^1.2.4
fast-defer: ^1.1.7
object-code: ^1.2.4
checksum: e7927101875a1e642f5459410c1bafba1e7b9fe69c5e488ece50b6e542eae24f2de025718d47aa17e3d3b9f27951e609b4aed8c7fe21d530d0e45be0cd1a04fd
object-code: ^1.3.0
peerDependencies:
axios: ^1
checksum: 1cda85f549f6471ba37938deda381e6b638c08e48363b803055b3e10bb4c854274a7bc206c2763efb23cc4b0a7f01285cb4fa7a4575fa8d9d65ded70b3512a59
languageName: node
linkType: hard

Expand Down Expand Up @@ -14768,10 +14770,10 @@ __metadata:
languageName: node
linkType: hard

"object-code@npm:^1.2.4":
version: 1.3.0
resolution: "object-code@npm:1.3.0"
checksum: bc5e3df85ac54785b3d1d9b8a9b2e168eb5f69e02be3c958fc05aebaa85ec659c55903852bf15ebf44e98053212f88eb7d3a9e28a50f10c4d60d820f80aa8d64
"object-code@npm:^1.3.0":
version: 1.3.1
resolution: "object-code@npm:1.3.1"
checksum: e3a1fad27fb5e53707202fb8ae5d23783bdb84663ee11c39df3e18d8540a8023ba17e23727acdbcb24a8ca7a5b9ea85bde3ce1fe3057e282e5c6d7e6880ba0ff
languageName: node
linkType: hard

Expand Down Expand Up @@ -17706,7 +17708,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^5.62.0
aws-sdk: ^2.1466.0
axios: ^1.5.1
axios-cache-interceptor: ^0.10.7
axios-cache-interceptor: ^1.3.2
basic-ftp: ^5.0.3
boom: ^7.3.0
bunyan: ^1.8.15
Expand Down