Skip to content

Latest commit

 

History

History
118 lines (84 loc) · 2.05 KB

template.md

File metadata and controls

118 lines (84 loc) · 2.05 KB

axios-storage

NPM

Language License

Caching adapter for axios.

Feature

  • Support localStoragesessionStoragememory mode
  • Support each request to be configured
  • Rerequest when the request parameter is inconsistent with the last request parameter

Install

Using npm:

npm install axios-storage --save

Using cdn:

<script src="https://unpkg.com/axios-storage/dist/axios-storage.js"></script>

Usage

You can use the axios-storage directly

import axios from 'axios';
import AxiosStorage from 'axios-storage';

// set global config
AxiosStorage.config({
    storagePrefix: 'axios-storage',
    storageMode: 'sessionStorage',
    maxAge: 120 * 60 * 1000
});

const api = axios.create({
    adapter: AxiosStorage.adapter
});

api({
    method: 'get',
    url: '/data',
    cacheConfig: {
        maxAge: 60 * 60 * 1000,
        storageMode: 'sessionStorage'
    }
})
.then(function(res){
    console.log(res);
})

api({
    method: 'get',
    url: '/data/other',
    cacheConfig: {
        maxAge: 60 * 60 * 1000,
        storageMode: 'localStorage'
    }
})
.then(function(res){
    console.log(res);
})

// or use global config
api({
    method: 'get',
    url: '/data/other',
    cacheConfig: true
})
.then(function(res){
    console.log(res);
})

#------------include------------#

Example

example

cd example && npm install
node app.js

after that,browser open http://localhost:3000/

Thanks

cachefactory

License

license