- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: new bundle setup & fixed development bundles (#167)
* feat: added issue template * fix: move dev bundles to a specific folder * docs: some documentation changes * docs: updated issue template * chore!: updated build setup * style: formatted code * chore: allow importing any file
1 parent
f699e19
commit 7293cf0
Showing
21 changed files
with
253 additions
and
205 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,11 +2,9 @@ | |
coverage | ||
node_modules | ||
|
||
/umd | ||
/cjs | ||
/esm | ||
# Output | ||
/dist | ||
/types | ||
/dev | ||
|
||
# Random | ||
/ignore | ||
|
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,50 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: 'bug: something is wrong :(' | ||
labels: bug | ||
assignees: arthurfiorette | ||
--- | ||
|
||
<!-- | ||
README | ||
Make sure to enable development mode before creating a issue, | ||
as it can print out the reason for a specific behavior. | ||
https://axios-cache-interceptor.js.org/#/pages/development-mode | ||
--> | ||
|
||
### Describe the bug | ||
|
||
<!-- | ||
A clear and concise description of what the bug is. | ||
--> | ||
|
||
### To Reproduce | ||
|
||
<!-- | ||
Provide a clear and concise description of how to reproduce the bug. | ||
It can be in form of a unit test, a snippet of code, a sequence of | ||
steps or a minimum reproduction repository. | ||
https://minimum-reproduction.wtf/ | ||
--> | ||
|
||
## Expected behavior | ||
|
||
<!-- | ||
A clear and concise description of what you expected to happen. | ||
--> | ||
|
||
### Additional context | ||
|
||
- Axios: `E.g: v0.26.1` | ||
- Axios Cache Interceptor: `E.g: v0.9.3` | ||
- What storage is being used: `E.g: Web Storage` | ||
- Node Version: `E.g: v16.9.1` | ||
- Browser (if applicable): `E.g: Chrome 98` | ||
|
||
<!-- | ||
Add any other context about the problem here. | ||
--> |
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 |
---|---|---|
|
@@ -2,11 +2,9 @@ | |
coverage | ||
node_modules | ||
|
||
/umd | ||
/cjs | ||
/esm | ||
# Output | ||
/dist | ||
/types | ||
/dev | ||
|
||
# Random | ||
/ignore | ||
|
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 |
---|---|---|
|
@@ -7,10 +7,7 @@ | |
|
||
!src/** | ||
|
||
!umd/** | ||
!cjs/** | ||
!esm/** | ||
!dist/** | ||
!dev/** | ||
|
||
!types/** | ||
|
||
!examples/runkit.js | ||
!examples/runkit.js |
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 |
---|---|---|
|
@@ -3,10 +3,7 @@ node_modules | |
/ignore | ||
/coverage | ||
/dist | ||
/umd | ||
/cjs | ||
/esm | ||
/types | ||
/dev | ||
/tsconfig.json | ||
|
||
.yarn | ||
|
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
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,26 @@ | ||
# Development | ||
|
||
For development, debug and testing purposes, you can opt to use the **Development mode**. | ||
#### TL;DR: `import { setupCache } from 'axios-cache-interceptor/dev';` | ||
|
||
It brings some extra features to our built code, like the `debug` option, source maps, | ||
fewer code and etc. | ||
All debugging information is emitted into a different bundle, this way it's possible to | ||
prevent unnecessary code from being bundled into the production build. | ||
|
||
You can enable it basically by using `/dev` at the end of the import path. | ||
Checkout how it helps debugging: | ||
|
||
```js | ||
import { setupCache } from 'axios-cache-interceptor/esm/dev'; | ||
const { setupCache } = require('axios-cache-interceptor/umd/dev'); | ||
```js #runkit | ||
const Axios = require('axios'); | ||
const { setupCache } = require('axios-cache-interceptor/dev'); | ||
|
||
// https://cdn.jsdelivr.net/npm/axios-cache-interceptor/umd/dev.js | ||
const { setupCache } = window.AxiosCacheInterceptor; | ||
``` | ||
|
||
## Debug option | ||
|
||
The debug option will print debug information in the console. It is good if you need to | ||
trace any undesired behavior or issue. | ||
|
||
You can enable it by setting `debug` to a function that receives an string. | ||
|
||
```js | ||
// Will print debug info in the console. | ||
setupCache(axios, { | ||
const axios = setupCache(Axios, { | ||
// Print all debug information to the console | ||
debug: console.log | ||
}); | ||
|
||
// own logger or whatever. | ||
setupCache(axios, { | ||
debug: (message) => { | ||
// Etc | ||
myCustomLogger.emit({ | ||
key: 'axios-cache-interceptor', | ||
log: message | ||
}); | ||
} | ||
}); | ||
const req1 = axios.get('https://jsonplaceholder.typicode.com/posts/1'); | ||
const req2 = axios.get('https://jsonplaceholder.typicode.com/posts/1'); | ||
|
||
// Disables debug. | ||
setupCache(axios, { | ||
debug: undefined | ||
}); | ||
// or | ||
axiosCacheInstance.debug = undefined; | ||
const [res1, res2] = await Promise.all([req1, req2]); | ||
|
||
console.log('Request 1:', res1.cached); | ||
console.log('Request 2:', res2.cached); | ||
``` |
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,92 @@ | ||
# Getting Started | ||
|
||
This library prevents every request made from being sent over the network. This is done by | ||
intercepting all requests and analyzing each one to see if that request has been made | ||
before. If it has, it will check if its not expired and return the cached response. If it | ||
hasn't, it will send the request over the network, as axios would do normally, and cache | ||
the response received for future requests. | ||
|
||
This library preserves 100% of the axios api, so after applying it with | ||
[`setupCache()`](pages/usage-examples#applying), your code won't change or break. | ||
|
||
```js #runkit | ||
const Axios = require('axios'); | ||
const { | ||
setupCache, | ||
buildMemoryStorage, | ||
defaultKeyGenerator, | ||
defaultHeaderInterpreter | ||
} = require('axios-cache-interceptor'); | ||
|
||
const axios = setupCache( | ||
// axios instance | ||
Axios.create(), | ||
|
||
// All options with their default values | ||
{ | ||
// The storage to save the cache data. There are more available by default. | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/storages | ||
storage: buildMemoryStorage(), | ||
|
||
// The mechanism to generate a unique key for each request. | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/request-id | ||
generateKey: defaultKeyGenerator, | ||
|
||
// The mechanism to interpret headers (when cache.interpretHeader is true). | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/global-configuration?id=headerinterpreter | ||
headerInterpreter: defaultHeaderInterpreter, | ||
|
||
// The function that will receive debug information. | ||
// NOTE: For this to work, you need to enable development mode. | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/development-mode | ||
// https://axios-cache-interceptor.js.org/#/pages/global-configuration?id=debug | ||
debug: undefined | ||
} | ||
); | ||
|
||
const { data } = await axios.get('url', { | ||
// All per-request options lives under the `cache` property. | ||
cache: { | ||
// The time until the cached value is expired in milliseconds. | ||
ttl: 1000 * 60 * 5, | ||
|
||
// If the request should configure the cache based on some standard cache headers, Like | ||
// Cache-Control, Expires and so on... | ||
interpretHeader: false, | ||
|
||
// All methods that should activate cache behaviors. If the method is not in this list, | ||
// it will be completely ignored. | ||
methods: ['get'], | ||
|
||
// A predicate object that will be used in each request to determine if the request can | ||
// be cached or not. | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/per-request-configuration?id=cachecachepredicate | ||
cachePredicate: { | ||
statusCheck: (status) => status >= 200 && status < 400 | ||
}, | ||
|
||
// All requests that should have their cache updated once this request is resolved. | ||
// Normally used to update similar requests or records with newer data. | ||
// | ||
// https://axios-cache-interceptor.js.org/#/pages/per-request-configuration?id=cacheupdate | ||
update: {}, | ||
|
||
// If the support for ETag and If-None-Match headers is active. You can use a string to | ||
// force a custom value for the ETag response. | ||
// | ||
etag: false, | ||
|
||
// If we should interpret the If-Modified-Since header when generating a TTL value. | ||
modifiedSince: false, | ||
|
||
// If we should return a old (possibly expired) cache when the current request failed | ||
// to get a valid response because of a network error, invalid status or etc. | ||
staleIfError: false | ||
} | ||
}); | ||
``` |
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
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 was deleted.
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
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