Git Product home page Git Product logo

got-cached's Introduction

got-cached

Got cached provides a cache wrapper around got

note: cache hits only include props response.status (200) and response.body

Install

$ npm install --save got-cached

Usage

gotChached takes options that should include a cache object that is expected to to have the functions set(key, value) and get(key) (returning a Promise that resolves the value).

Below is an example using then-redis to cache with a 10 minute expiry

import { createClient } from 'then-redis'
import gotCached from 'got-cached'

const expiry = 600
const redis = createClient()
const options = {
  cache: {
    get: (key) => redis.get(key),
    set: (key, value) => redis.send('set', [key, value, 'EX', expiry])
  }
}

const got = gotCached(options)

got('http://httpbin.org/get').then((response) => {
  console.log(response.body)
})

got-cached's People

Watchers

Janne Lönn avatar James Cloos avatar

Forkers

beevelop

got-cached's Issues

Make got a peer dependency

Got is heavily outdated in package.json. It would be better to make it a peer dependency such that every user can have their own (updated) version of it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.