Skip to content

Instantly share code, notes, and snippets.

@ilyapasyuk
Created March 10, 2020 23:13
Show Gist options
  • Save ilyapasyuk/df1744d9e63926968e19e41ef7533ca6 to your computer and use it in GitHub Desktop.
Save ilyapasyuk/df1744d9e63926968e19e41ef7533ca6 to your computer and use it in GitHub Desktop.
Cache in Axios
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