How to use the axios-cache-adapter.setup function in axios-cache-adapter

To help you get started, we’ve selected a few axios-cache-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RasCarlito / axios-cache-adapter / examples / basic.js View on Github external
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)
github zenghongtu / Remu / src / utils.ts View on Github external
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)
      );
github PeteAndersen / swarfarm / frontend / src / services / api.js View on Github external
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)

axios-cache-adapter

Caching adapter for axios

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular axios-cache-adapter functions