JSPM

  • Created
  • Published
  • Downloads 161878
  • Score
    100M100P100Q183535F
  • License MIT

Cache interceptor for axios

Package Exports

  • axios-cache-interceptor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (axios-cache-interceptor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


  

🗄️📦💿 Axios Cache Interceptor




Forks Issues Stars License Npm



This library is in beta and can have breaking changes until v1.
Not ready for production usage!


axios-cache-interceptor is a axios wrapper for caching and preventing unneeded requests


import axios from 'axios';
import { createCache, SessionCacheStorage } from 'axios-cache-interceptor';

// Any custom axios instance
const api = axios.create();

// Other axios instance with caching enabled
const cachedApi = createCache(api, {
  // Store values on window.sessionStorage
  storage: new SessionCacheStorage(),

  // Use the max-age header to determine the cache expiration time
  interpretHeader: true
});

// Make a requests that's only cached if the response comes with success header
cachedApi.get('http://example.com/', {
  cache: {
    cachePredicate: {
      containsHeaders: ['success']
    }
  }
});


Installing

Axios is a peer dependency and must be installed separately.

# Npm
npm install --save axios axios-cache-interceptor

# Yarn
yarn add axios axios-cache-interceptor

Inspiration

This project is highly inspired by several projects, written entirely in typescript, supporting https headers and much more.

Take a look at some similar projects:


License

Licensed under the MIT. See LICENSE for more informations.


Contact

See my contact information on my github profile or open a new issue.