1.0.7 • Published 2 years ago

axios_enhance_tool v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

axios_enhance_tool

  • ✅ 自定义的axios_adpter,目前实现了接口请求缓存功能
  • ✅ 使用LRU控制缓存,可配置缓存时间和缓存个数
  • ✅ 支持全局开启和单个接口开启
  • ✅ 默认只能开启get/post的缓存
  • ✅ 当前使用"axios": "^1.4.0",

安装

使用npm安装:

npm install axios_adapter_enhance

使用方法

示例代码:

import cachingAdapter, { setupAdapter } from 'axios_adapter_enhance';

const cache = setupAdapter({ defaultUse: true });

const axiosWithCache = new axios.create({
  adapter: cache.adapter
});
  

// 测试用例
    axiosWithCache.get('https://api.github.com/users/github').then(response => {
      console.log(response.data);
    });  
    setTimeout(() => {
      axiosWithCache.get('https://api.github.com/users/github', {
        cachePath: '/users/github'
      }).then(response => {
        console.log(response.data);
      });
    }, 100);

选项

setupAdapter函数参数

参数默认值描述
defaultUsefalse是否全局开启缓存
cacheCount10最大缓存请求的个数
cacheTime60000最大缓存时间(单位ms)

贡献者

如果您想了解更多有关如何贡献或加入该项目的信息,请点击此处

许可证

MIT License

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago