Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-cache-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-cache-interceptor

Cache interceptor for axios

  • 1.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
122K
decreased by-3.45%
Maintainers
1
Weekly downloads
 
Created

What is axios-cache-interceptor?

The axios-cache-interceptor package is a middleware for Axios that provides caching capabilities. It allows you to cache HTTP requests and responses, reducing the number of network requests and improving performance.

What are axios-cache-interceptor's main functionalities?

Basic Caching

This feature allows you to set up basic caching for your Axios requests. The example demonstrates how to create a cache with a maximum age of 15 minutes and use it with an Axios instance.

const axios = require('axios');
const { setupCache } = require('axios-cache-interceptor');

const cache = setupCache({
  maxAge: 15 * 60 * 1000 // 15 minutes
});

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

api.get('https://api.example.com/data')
  .then(response => console.log(response.data))
  .catch(error => console.error(error));

Custom Cache Key

This feature allows you to define a custom cache key. The example shows how to create a cache key based on the request URL, method, and parameters.

const axios = require('axios');
const { setupCache } = require('axios-cache-interceptor');

const cache = setupCache({
  key: req => req.url + req.method + JSON.stringify(req.params)
});

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

api.get('https://api.example.com/data', { params: { id: 1 } })
  .then(response => console.log(response.data))
  .catch(error => console.error(error));

Cache Invalidation

This feature allows you to manually invalidate the cache for specific requests. The example demonstrates how to invalidate the cache for a specific URL.

const axios = require('axios');
const { setupCache } = require('axios-cache-interceptor');

const cache = setupCache();

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

api.get('https://api.example.com/data')
  .then(response => console.log(response.data))
  .catch(error => console.error(error));

// Invalidate the cache for a specific request
cache.invalidate({ url: 'https://api.example.com/data' });

Other packages similar to axios-cache-interceptor

Keywords

FAQs

Package last updated on 13 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc