Skip to content

Instantly share code, notes, and snippets.

@ErikGMatos
Last active September 10, 2020 15:51
Show Gist options
  • Save ErikGMatos/cd7b6aee44fde1a5c1c394176b78094c to your computer and use it in GitHub Desktop.
Save ErikGMatos/cd7b6aee44fde1a5c1c394176b78094c to your computer and use it in GitHub Desktop.
intância do axios com axios-cache-adapter
import { setup } from 'axios-cache-adapter';
import localforage from 'localforage';
import memoryDriver from 'localforage-memoryStorageDriver';
import { getURLCached } from './cache';
localforage.defineDriver(memoryDriver);
const localforageStore = localforage.createInstance({
driver: [localforage.LOCALSTORAGE, localforage.INDEXEDDB],
name: 'NOME_QUE APARECE_NO_LOCALSTORAGE',
});
const api = setup({
baseURL: 'https://meusite.com/api',
cache: {
maxAge: 2 * 60 * 1000,
store: localforageStore,
exclude: {
filter: req => getURLCached(req), // true não cacheia, false cacheia
query: false,
},
},
});
export default api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment