1.1.4 • Published 1 year ago
axios-cacher v1.1.4
Axios Cacher
Cache the response from endpoints and easily invalidate the cache
Install
npm install --save axios-cacherUsage
Step 1
Import
import setup from "axios-cacher";Step 2
This package exposes a setup function which can be used as follows:
const { axiosClient, invalidateThis } = setup({
// base url for your axios config
baseURL: baseURL,
// your axios config headers
headers: {
Accept: "application/vnd.api+json; version=1.0"
},
// cache configuration
cache: {
// cache expires after 5 minutes
maxAge: 5 * 60 * 1000,
// function to invalidate cache
invalidate: async (config, request) => {
if (request.clearCacheEntry) {
await config.store.removeItem(config.uuid);
}
},
}
});Step 3
You can use axiosClient in step 1 to make api calls
const response = await axiosClient.get(
url,
{ userKey: "test" }
);Any request after this from the same url will be fetched from the cache for 5 minutes(for this example) unless you invalidate it before. Pass the userKey as shown above so that you can invalidate it using the invalidateThis function.
Use the invalidate function as follows:
invalidateThis(userKey);1.1.1
1 year ago
1.0.19
1 year ago
1.1.0
1 year ago
1.0.18
1 year ago
1.1.4
1 year ago
1.1.3
1 year ago
1.1.2
1 year ago
1.0.21
1 year ago
1.0.20
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.17
1 year ago
1.0.16
1 year ago
1.0.9
1 year ago
1.0.7
1 year ago
1.0.6
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.11
1 year ago
1.0.10
1 year ago
1.0.15
1 year ago
1.0.14
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.0
1 year ago