axios-storage
Caching adapter for axios.
Feature
- Support
localStorage
、sessionStorage
、memory
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:
Usage
You can use the axios-storage directly
;; // set global configAxiosStorage; const api = axios; // or use global config
API
AxiosStorage.config(options)
global config options, see all options
Param | Type | Default | Description |
---|---|---|---|
options | object |
||
[options.storagePrefix] | string |
"axios-storage" |
thhe prefix of storage |
[options.storageMode] | string |
"sessionStorage" |
the mode of storage,support localStorage 、sessionStorage 、memory |
[options.deleteOnExpire] | string |
"aggressive" |
how to handler expired storage |
Example
;; AxiosStorage;
AxiosStorage.adapter()
adapter
Example
;; const api = axios; apiapi
object
AxiosStorage.getCache(options) ⇒ Cache Object
Returns: object
- Cache,see detail Cache
Param | Type | Default | Description |
---|---|---|---|
options | object | string |
||
[options.storageMode] | string |
"sessionStorage" |
storage mode |
Example
let oCache = AxiosStorage; oCache;oCache; // "bar"... // request data with cacheConfig // get this request cachelet res = oCache // `res` is the same as above oCache // `method` is uppercase, GET、POST etc.
Example
cd example && npm install
node app.js
after that,browser open http://localhost:3000/