mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
20 lines
569 B
TypeScript
20 lines
569 B
TypeScript
// @ts-nocheck
|
|
// Readme example
|
|
|
|
import axios from 'axios';
|
|
import { createCache, SessionCacheStorage } from '../src/index';
|
|
|
|
// 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 simple request, with caching support, to the api
|
|
const { data } = await cachedApi.get('https://api.example.com/'); |