Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {setup} = require('axios-cache-adapter')
// Create an `axios` instance with `axios-cache-adapter` pre-configured
const api = setup({
// `axios` options
baseURL: 'https://httpbin.org',
// `axios-cache-adapter` options
cache: {
// Cache expiration in milliseconds, here 15min
maxAge: 15 * 60 * 1000,
// Cache exclusion rules
exclude: {
// Store responses from requests with query parameters in cache
query: false
}
}
})
// Make a request to https://httpbin.org/get?foo=bar (runkit handles what appears to be a top-level await)
import Axios from 'axios';
import { Modal, notification, message } from 'antd';
import { setupCache, setup } from 'axios-cache-adapter';
import localforage from 'localforage';
const baseURL = 'https://api.github.com';
export const forageStore = localforage.createInstance({
// List of drivers used
driver: [localforage.INDEXEDDB, localforage.LOCALSTORAGE],
// Prefix all storage keys to prevent conflicts
name: 'remu-cache',
});
export const request = setup({
baseURL,
cache: {
maxAge: 60 * 60 * 1000,
exclude: { query: false },
store: forageStore,
invalidate: async (config, request) => {
if (request.clearCacheEntry) {
// @ts-ignore
await config.store.removeItem(config.uuid);
}
},
readOnError: (error, request) => {
return (
!error.response ||
(error.response.status >= 500 && error.response.status < 600)
);
import { setup } from "axios-cache-adapter";
const apiRoot =
process.env.NODE_ENV === "development"
? "http://127.0.0.1:8000/api/v2"
: "https://swarfarm.com/api/v2";
const api = setup({
baseURL: apiRoot,
withCredentials: true,
cache: {
maxAge: 15 * 60 * 1000,
exclude: {
query: false,
filter: config => config.url.startsWith("/profiles"),
},
},
});
if (process.env.NODE_ENV === "development") {
api.interceptors.response.use(
function(response) {
const params = response.config.params
? Object.keys(response.config.params)