Skip to content

Commit

Permalink
docs: updated benchmark and fixed some typos
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Mar 11, 2022
1 parent 09a69f8 commit 08d7ab4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion docs/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { writeFileSync } = require('fs');
const Axios = require('axios').default;
const AxiosInstance = Axios.create();

const AxiosCacheInterceptor = require('../cjs');
const AxiosCacheInterceptor = require('../dist/index.cjs');
const InterceptorInstance = AxiosCacheInterceptor.setupCache(Axios.create());

const AxiosCacheAdapter = require('axios-cache-adapter');
Expand Down
18 changes: 9 additions & 9 deletions docs/pages/_comparison-benchmark.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Result

Run at Fri, 04 Mar 2022 16:50:35 GMT
Commit: 41d9fe1d4d94c547a25afb5ce3985486f949f0d3
Run at Fri, 11 Mar 2022 20:06:31 GMT
Commit: 09a69f80069f474f65bf58bc23bc71c8e511c84d


CACHE INTERCEPTOR
Operations: 44556/s
Network requests: 1 of 218002
Operations: 49413/s
Network requests: 1 of 242600
Performance: 100%

CACHE ADAPTER
Operations: 38311/s
Network requests: 2 of 185666
Performance: 86%
Operations: 43404/s
Network requests: 2 of 210319
Performance: 88%

AXIOS
Operations: 1952/s
Network requests: 9639 of 9639
Operations: 2163/s
Network requests: 10519 of 10519
Performance: 4%
6 changes: 3 additions & 3 deletions docs/pages/request-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ A good thing to know is that every request passed through this interceptor, has
most important is to bind a request to its cache.

The id generation is good enough to generate the same id for theoretically sames requests.
The example of this is a request with `{ baseURL: 'https://a.com/', url: '/b' }` results
to the same id with `{ url: 'https://a.com/b/' }`.
A simple example is a request with `{ baseURL: 'https://a.com/', url: '/b' }` results to
the same id with `{ url: 'https://a.com/b/' }`.

Also, a custom id can be used to treat two requests as the same.

Expand Down Expand Up @@ -41,7 +41,7 @@ id generation can clarify this idea.

## Joining requests

two requests will be treated as the same if they have the same `id` property. If it was
Two requests will be treated as the same if they have the same `id` property. If it was
not defined, it will be auto generated by the provided `Key Generator`.

You can override their `id` property by providing a custom one.
Expand Down
11 changes: 4 additions & 7 deletions docs/pages/storages.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ is reached.

The eviction is done by the following algorithm:

1. Saves an value and got an error. (Probably quota exceeded)
1. Saves an value and got an error. _(Probably quota exceeded)_
2. Evicts all expired keys that cannot enter the `stale` state.
3. If it fails again, evicts the oldest key.
4. Repeat step 4 and 5 until the object could be saved or the storage is empty.
Expand All @@ -102,9 +102,6 @@ The eviction is done by the following algorithm:
There's no mystery implementing a custom storage. You can create your own storage by using
the `buildStorage` function. It is also internally used to build the built-in ones.

This function is needed to add a simple method `get`. It is used to retrieve the value of
a key and handle cache invalidation.

Look at this simple [NodeRedis v4](https://github.com/redis/node-redis) example.

```js
Expand All @@ -115,16 +112,16 @@ const { buildStorage, setupCache } = require('axios-cache-interceptor');
const client = createClient();

const redisStorage = buildStorage({
find: async (key) => {
async find(key) {
const result = await client.get(`axios-cache:${key}`);
return JSON.parse(result);
},

set: async (key, value) => {
async set(key, value) {
await client.set(`axios-cache:${key}`, JSON.stringify(value));
},

remove: async (key) => {
async remove(key) {
await client.del(`axios-cache:${key}`);
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/storage/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ declare const structuredClone: (<T>(value: T) => T) | undefined;
*
* If you need to modify it's data, you can do by the `data` property.
*
* @param {boolean} cloneData if the data returned by `find()` should be cloned to avoid mutating the original data outside the `set()` method.
*
* @example
*
* ```js
Expand All @@ -31,6 +29,9 @@ declare const structuredClone: (<T>(value: T) => T) | undefined;
*
* delete memoryStorage.data[id];
* ```
*
* @param {boolean} cloneData If the data returned by `find()` should be cloned to avoid
* mutating the original data outside the `set()` method.
*/
export function buildMemoryStorage(cloneData = false) {
const storage = buildStorage({
Expand Down
38 changes: 19 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@discoveryjs/json-ext@^0.5.0":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.6.tgz#d5e0706cf8c6acd8c6032f8d54070af261bbbb2f"
integrity sha512-ws57AidsDvREKrZKYffXddNkyaF14iHNHm8VQnZH6t99E8gczjNN0GpvcGny0imC80yQ0tHz1xVUKk/KFQSUyA==
version "0.5.7"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@eslint/eslintrc@^1.2.0":
version "1.2.0"
Expand Down Expand Up @@ -1268,12 +1268,12 @@ browser-process-hrtime@^1.0.0:
integrity sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==

browserslist@^4.14.5, browserslist@^4.17.5:
version "4.19.3"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.3.tgz#29b7caad327ecf2859485f696f9604214bedd383"
integrity sha512-XK3X4xtKJ+Txj8G5c30B4gsm71s69lqXlkYui4s6EkKxuv49qjYlY6oVd+IFJ73d4YymtM3+djvvt/R/iJwwDg==
version "4.20.0"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.0.tgz#35951e3541078c125d36df76056e94738a52ebe9"
integrity sha512-bnpOoa+DownbciXj0jVGENf8VYQnE2LNWomhYuCsMmmx9Jd9lwq0WXODuwpSsp8AVdKM2/HorrzxAfbKvWTByQ==
dependencies:
caniuse-lite "^1.0.30001312"
electron-to-chromium "^1.4.71"
caniuse-lite "^1.0.30001313"
electron-to-chromium "^1.4.76"
escalade "^3.1.1"
node-releases "^2.0.2"
picocolors "^1.0.0"
Expand Down Expand Up @@ -1317,10 +1317,10 @@ camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001312:
version "1.0.30001313"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001313.tgz#a380b079db91621e1b7120895874e2fd62ed2e2f"
integrity sha512-rI1UN0koZUiKINjysQDuRi2VeSCce3bYJNmDcj3PIKREiAmjakugBul1QSkg/fPrlULYl6oWfGg3PbgOSY9X4Q==
caniuse-lite@^1.0.30001313:
version "1.0.30001314"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001314.tgz#65c7f9fb7e4594fca0a333bec1d8939662377596"
integrity sha512-0zaSO+TnCHtHJIbpLroX7nsD+vYuOVjl3uzFbJO1wMVbuveJA0RK2WcQA9ZUIOiO0/ArMiMgHJLxfEZhQiC0kw==

chalk@3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -1631,10 +1631,10 @@ domexception@^2.0.1:
dependencies:
webidl-conversions "^5.0.0"

electron-to-chromium@^1.4.71:
version "1.4.75"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.75.tgz#d1ad9bb46f2f1bf432118c2be21d27ffeae82fdd"
integrity sha512-LxgUNeu3BVU7sXaKjUDD9xivocQLxFtq6wgERrutdY/yIOps3ODOZExK1jg8DTEg4U8TUCb5MLGeWFOYuxjF3Q==
electron-to-chromium@^1.4.76:
version "1.4.82"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.82.tgz#51e123ca434b1eba8c434ece2b54f095b304a651"
integrity sha512-Ks+ANzLoIrFDUOJdjxYMH6CMKB8UQo5modAwvSZTxgF+vEs/U7G5IbWFUp6dS4klPkTDVdxbORuk8xAXXhMsWw==

emittery@^0.8.1:
version "0.8.1"
Expand Down Expand Up @@ -3982,9 +3982,9 @@ typescript@^4.5.4:
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==

uglify-js@^3.1.4:
version "3.15.2"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.15.2.tgz#1ed2c976f448063b1f87adb68c741be79959f951"
integrity sha512-peeoTk3hSwYdoc9nrdiEJk+gx1ALCtTjdYuKSXMTDqq7n1W7dHPqWDdSi+BPL0ni2YMeHD7hKUSdbj3TZauY2A==
version "3.15.3"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.15.3.tgz#9aa82ca22419ba4c0137642ba0df800cb06e0471"
integrity sha512-6iCVm2omGJbsu3JWac+p6kUiOpg3wFO2f8lIXjfEb8RrmLjzog1wTPMmwKB7swfzzqxj9YM+sGUM++u1qN4qJg==

unist-util-stringify-position@^2.0.0:
version "2.0.3"
Expand Down

0 comments on commit 08d7ab4

Please sign in to comment.