Created
March 10, 2020 23:13
-
-
Save ilyapasyuk/df1744d9e63926968e19e41ef7533ca6 to your computer and use it in GitHub Desktop.
Cache in Axios
This file contains hidden or 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
import axios from 'axios'; | |
import { cacheAdapterEnhancer } from 'axios-extensions'; | |
const http = axios.create({ | |
baseURL: '/', | |
headers: { 'Cache-Control': 'no-cache' }, | |
// cache will be enabled by default | |
adapter: cacheAdapterEnhancer(axios.defaults.adapter) | |
}); | |
http.get('/users'); // make real http request | |
http.get('/users'); // use the response from the cache of previous request, without real http request made | |
http.get('/users', { cache: false }); // disable cache manually and the the real http request invoked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment