Last active
September 10, 2020 15:51
-
-
Save ErikGMatos/cd7b6aee44fde1a5c1c394176b78094c to your computer and use it in GitHub Desktop.
intância do axios com axios-cache-adapter
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 { 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