simple-swr
v1.0.2
Published
SimpleSWR is a lightweight and efficient caching adapter for Axios.
Downloads
5
Maintainers
Readme
SimpleSWR
SimpleSWR is a lightweight and efficient caching adapter for Axios, implementing the Stale While Revalidate (SWR) strategy. It's designed to enhance the performance of HTTP requests by caching responses and revalidating them in the background.
Because of its simplicity, it can be used in a variety of repositories for data state management, including Vue's Pinia.
Key Features:
- Efficient Caching: Reduce network load by caching Axios responses.
- SWR Strategy: Automatically revalidate cached data to ensure freshness.
- Easy Integration: Seamlessly integrates with existing Axios instances.
Installation
npm i simple-swr
Quick Start
// Example of using SimpleSWR
import simpleSWR from 'simple-swr';
// Fetch response with caching
const response = await simpleSWR.get('/api/example');
const data = response.data;
Parameters
// You can also setup cache duration
simpleSWR.setup({ cacheDuration: 1000 * 60 * 5 });