npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

axios-cache-adapter-node

v1.5.7

Published

Caching adapter for axios

Downloads

17

Readme

axios-cache-adapter

Caching adapter for axios

Adapted from superapi-cache by @stephanebachelier

Install

Using npm

npm install --save axios-cache-adapter

Or bower

bower install --save axios-cache-adapter

Or from a CDN like unpkg.com

<script type="text/javascript" src="https://unpkg.com/axios-cache-adapter"></script>

PS: For bower users there is a limitation, this library uses lodash-es as a dependency which is not published on bower. If you use bower, use the bundled version of the lib dist/cache.bundled.js

Usage

You can use the adapter directly

import axios from 'axios'
import { setupCache } from 'axios-cache-adapter'

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

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

api({
  url: 'http://some-rest.api/url',
  method: 'get'
}).then(response => {
  // Do something fantastic with response.data \o/
})

Or you can get an instance of axios pre-configured with the cache adapter

import { setup } from 'axios-cache-adapter'

const api = setup({
  cache: {
    maxAge: 15 * 60 * 1000
  }
})

api({
  url: 'http://some-reset.api/url',
  method: 'get'
}).then(response => {
  // Do something awesome with response.data \o/
})

API

setupCache(options)

Create a cache adapter instance. Takes an options object to configure how the cached requests will be handled, where they will be stored, etc.

Options

  • maxAge {Number}: Maximum time for storing each request in milliseconds, defaults to 15 minutes (15 * 60 * 1000)
  • store {Object}: An instance of localForage, defaults to a custom in memory store
  • clearOnStale {Boolean}: Clear cache when it is stale, defaults to true
  • exclude {Object}: Object defining which kind of requests should be excluded from cache
    • filter {Function}: A method which receives the request and returns true to exclude request from cache, defaults to null
    • query {Boolean}: If true all requests containing a query will be excluded, defaults to false
    • paths {Array}: An Array of regular expressions to match against request URLs, if a match is found it will be excluded, defaults to []
  • debug {Boolean}: Print some logs to console, defaults to false

Returns

setupCache() returns an object containing the configured adapter and the cache store.

setup(options)

Create an axios instance pre-configured with the cache adapter. Takes an options object to configure the cache and axios at the same time.

Options

  • cache {Object}: Same options as the setupCache method

All the other parameters passed in the options will be passed directly to the axios.create method.

Returns

setup() returns an instance of axios pre-configured with the cache adapter.

License

MIT © Carl Ogren