1.1.4 • Published 9 months ago

axios-cacher v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Axios Cacher

Cache the response from endpoints and easily invalidate the cache

Install

npm install --save axios-cacher

Usage

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

9 months ago

1.0.19

9 months ago

1.1.0

9 months ago

1.0.18

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.17

9 months ago

1.0.16

10 months ago

1.0.9

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.0

10 months ago