Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@devgaoy/axios-strong

knightgao6MIT1.0.1

axios的扩展,使支持缓存

readme

@gaoy/axios-strong

axios 的扩展,使得他支持缓存

Installing

npm i @devgaoy/axios-strong -S

使用例子

import { cacheAdapterEnhancer } from "@devgaoy/axios-strong";
const myaxios = axios.create({
  baseURL: base,
  timeout: 10000, // 请求超时时间
  adapter: cacheAdapterEnhancer(axios.defaults.adapter, {
    enabledByDefault: false, // 默认是否走缓存
    cacheFlag: "cache", //默认的Flag
    maxAge: 5 * 60 * 1000, // 缓存过期时间
    max: 100, //最多允许的缓存
  }),
});
myaxios.get("/users", { cache: true }); // 发请求了
myaxios.get("/users", { cache: true }); // 没法请求,走了缓存
myaxios.get("/users", { cache: false }); // 不走缓存 发了请求

Heavily inspired by axios-extensions