fetchache
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

Fetchache

A fetch wrapper that allows you to respect HTTP caching strategies on non-browser environments with a key-value cache implementation. It follows the HTTP Caching and Conditional Requests standards.

Installation

yarn add fetchache

Usage

import { fetchFactory } from 'fetchache'
import { fetch, Response } from 'some-fetch-impl'

// We recommend using `@whatwg-node/fetch`

const someCacheImpl = {
  get: async key => {
    // Get the cached value from your cache implementation
  },
  set: async (key, value) => {
    // Set the cached value to your cache implementation
  }
}

const fetchWithCache = fetchFactory({
  fetch,
  Response,
  cache
})

// Then you can use it like a normal fetch
const response = await fetchWithCache('https://example.com')

/fetchache/

    Package Sidebar

    Install

    npm i fetchache

    Weekly Downloads

    1,545

    Version

    0.1.6

    License

    MIT

    Unpacked Size

    13.3 kB

    Total Files

    7

    Last publish

    Collaborators

    • ardatan