Skip to content

Commit 8df465d

Browse files
committed
fix: use defaultAxiosCacheAdapterKeyFixed
lisaogren/axios-cache-adapter#250
1 parent 0e02007 commit 8df465d

File tree

8 files changed

+88
-3
lines changed

8 files changed

+88
-3
lines changed

packages/@bluelovers/axios-extend/lib/cache.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@bluelovers/axios-extend/lib/cache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ITSPartialPick } from 'ts-type';
88
import { IAxiosCacheAdapterOptionsConfig } from './types';
99
import { CacheStoreByMapLike } from 'axios-cache-adapter-util/lib/createCacheStoreByMapLike';
1010
import LRUCache from 'lru-cache2';
11+
import { defaultAxiosCacheAdapterKeyFixed } from 'axios-cache-adapter-util/lib/util/key';
1112

1213
export { IAxiosCacheAdapterOptions, ISetupCache, IAxiosCacheAdapterOptionsConfig }
1314

@@ -54,7 +55,8 @@ export function mixinCacheConfig<T extends IAxiosCacheAdapterOptionsConfig>(conf
5455
{
5556
return res.status >= 500;
5657
}
57-
}
58+
},
59+
key: defaultAxiosCacheAdapterKeyFixed,
5860
})
5961
}
6062

packages/@bluelovers/axios-extend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
"@types/bluebird": "*",
4141
"@types/follow-redirects": "^1.13.1",
4242
"axios-cache-adapter": "*",
43+
"axios-cache-adapter-util": "^1.0.53",
4344
"axios-cookiejar-support": "*",
4445
"bluebird": "*",
4546
"get-value": "^3.0.1",
4647
"lodash": "^4",
48+
"lru-cache2": "^6.0.7",
4749
"reflect-metadata-util": "^1.0.12",
4850
"retry-axios": "^2.4.0",
4951
"ts-type": "^1.2.39",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { AxiosRequestConfig } from 'axios';
2+
declare module 'axios-cache-adapter' {
3+
function serializeQuery(req: Pick<AxiosRequestConfig, 'params'>): string;
4+
}
5+
/**
6+
* bug fixed version of key
7+
*
8+
* @see https://github.com/RasCarlito/axios-cache-adapter/blob/master/src/cache.js#L66
9+
* @see https://github.com/RasCarlito/axios-cache-adapter/pull/250
10+
*/
11+
export declare function defaultAxiosCacheAdapterKeyFixed(req: AxiosRequestConfig): string;
12+
export declare function axiosCacheAdapterKeyExtra(cb: (req: Partial<AxiosRequestConfig>) => Pick<AxiosRequestConfig, 'url' | 'baseURL' | 'data' | 'params'>): (req: AxiosRequestConfig) => string;

packages/axios-cache-adapter-fs/lib/util/key.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import md5 from 'md5'
2+
import { serializeQuery } from 'axios-cache-adapter'
3+
import { LazyURL } from 'lazy-url'
4+
import { AxiosRequestConfig } from 'axios';
5+
6+
declare module 'axios-cache-adapter'
7+
{
8+
function serializeQuery(req: Pick<AxiosRequestConfig, 'params'>): string;
9+
}
10+
11+
/**
12+
* bug fixed version of key
13+
*
14+
* @see https://github.com/RasCarlito/axios-cache-adapter/blob/master/src/cache.js#L66
15+
* @see https://github.com/RasCarlito/axios-cache-adapter/pull/250
16+
*/
17+
export function defaultAxiosCacheAdapterKeyFixed(req: AxiosRequestConfig)
18+
{
19+
const url = new LazyURL(req.url, req.baseURL).toRealString();
20+
const key = url + serializeQuery(req)
21+
return req.data ? key + md5(req.data) : key
22+
}
23+
24+
export function axiosCacheAdapterKeyExtra(cb: (req: Partial<AxiosRequestConfig>) => Pick<AxiosRequestConfig, 'url' | 'baseURL' | 'data' | 'params'>)
25+
{
26+
return (req: AxiosRequestConfig) => {
27+
return defaultAxiosCacheAdapterKeyFixed(cb(req))
28+
}
29+
}

packages/axios-cache-adapter-fs/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"license": "ISC",
2525
"author": "",
2626
"main": "./lib/index",
27+
"types": "./lib/index.d.ts",
28+
"typings": "./lib/index.d.ts",
2729
"scripts": {
2830
"coverage": "npx nyc npm run test",
2931
"lint": "npx eslint **/*.ts",
@@ -37,12 +39,15 @@
3739
"bluebird": "^3.7.2",
3840
"free-gc": "^1.0.6",
3941
"fs-extra": "^10.0.0",
42+
"lazy-url": "^1.0.12",
43+
"md5": "^2.3.0",
4044
"restful-decorator": "^1.0.57",
4145
"ts-type": "^1.2.39",
4246
"tslib": "^2.3.0",
4347
"typed-http-headers": "^1.0.7"
4448
},
4549
"devDependencies": {
50+
"@types/md5": "^2.3.1",
4651
"fs-extra": "^10.0.0",
4752
"lru-cache2": "^6.0.7"
4853
},

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,13 @@
11371137
resolved "https://registry.npmjs.org/@types/luxon/-/luxon-1.27.1.tgz#aceeb2d5be8fccf541237e184e37ecff5faa9096"
11381138
integrity sha512-cPiXpOvPFDr2edMnOXlz3UBDApwUfR+cpizvxCy0n3vp9bz/qe8BWzHPIEFcy+ogUOyjKuCISgyq77ELZPmkkg==
11391139

1140+
"@types/md5@^2.3.1":
1141+
version "2.3.1"
1142+
resolved "https://registry.npmjs.org/@types/md5/-/md5-2.3.1.tgz#010bcf3bb50a2cff3a574cb1c0b4051a9c67d6bc"
1143+
integrity sha512-OK3oe+ALIoPSo262lnhAYwpqFNXbiwH2a+0+Z5YBnkQEwWD8fk5+PIeRhYA48PzvX9I4SGNpWy+9bLj8qz92RQ==
1144+
dependencies:
1145+
"@types/node" "*"
1146+
11401147
"@types/moment-timezone@^0.5.30":
11411148
version "0.5.30"
11421149
resolved "https://registry.npmjs.org/@types/moment-timezone/-/moment-timezone-0.5.30.tgz#340ed45fe3e715f4a011f5cfceb7cb52aad46fc7"
@@ -3694,7 +3701,7 @@ [email protected]:
36943701
resolved "https://registry.npmjs.org/marked/-/marked-0.8.2.tgz#4faad28d26ede351a7a1aaa5fec67915c869e355"
36953702
integrity sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==
36963703

3697-
md5@^2.2.1:
3704+
md5@^2.2.1, md5@^2.3.0:
36983705
version "2.3.0"
36993706
resolved "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
37003707
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==

0 commit comments

Comments
 (0)