All Projects β†’ transitive-bullshit β†’ p-cache

transitive-bullshit / p-cache

Licence: other
Decorator to memoize the results of async functions via lru-cache.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to p-cache

ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (+28.57%)
Mutual labels:  promise
design-patterns-cpp14
πŸ™ Design patterns implemented in C++14
Stars: ✭ 35 (+66.67%)
Mutual labels:  memoize
rmfr
Node.js implementation of rm -fr – recursive removal of files and directories
Stars: ✭ 23 (+9.52%)
Mutual labels:  promise
etsy-ts
Etsy API wrapper written in typescript
Stars: ✭ 18 (-14.29%)
Mutual labels:  promise
miniprogram-network
Redefine the Network API of Wechat MiniProgram (ε°η¨‹εΊη½‘η»œεΊ“)
Stars: ✭ 93 (+342.86%)
Mutual labels:  promise
PromisedFuture
A Swift based Future/Promises framework to help writing asynchronous code in an elegant way
Stars: ✭ 75 (+257.14%)
Mutual labels:  promise
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> πŸ‚ -> πŸš€
Stars: ✭ 18 (-14.29%)
Mutual labels:  promise
eslint-config-welly
😎 βš™οΈ ESLint configuration for React projects that I do. Feel free to use this!
Stars: ✭ 21 (+0%)
Mutual labels:  promise
wtsqs
Simplified Node AWS SQS Worker Wrapper
Stars: ✭ 18 (-14.29%)
Mutual labels:  promise
promise-abortable
Promise lib for aborting in chain.
Stars: ✭ 19 (-9.52%)
Mutual labels:  promise
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+390.48%)
Mutual labels:  promise
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (+152.38%)
Mutual labels:  promise
nodeJS examples
Server, routing, db examples using NodeJS v6
Stars: ✭ 34 (+61.9%)
Mutual labels:  promise
nancy
How JavaScript Promise Works
Stars: ✭ 26 (+23.81%)
Mutual labels:  promise
repromised
🀝 Declarative promise resolver as a render props component
Stars: ✭ 20 (-4.76%)
Mutual labels:  promise
mst-effect
πŸ’« Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-9.52%)
Mutual labels:  promise
co demo
A step-by-step guide about how to avoid callback hell with ES6 Promises + generators (aka make your own "co")
Stars: ✭ 17 (-19.05%)
Mutual labels:  promise
best-queue
Queue in runtime based promise
Stars: ✭ 26 (+23.81%)
Mutual labels:  promise
relaks
Asynchrounous React component
Stars: ✭ 49 (+133.33%)
Mutual labels:  promise
PiedPiper
A small set of classes and functions to make easy use of Futures, Promises and async computation in general. All written in Swift for iOS 10+, WatchOS 3, tvOS and Mac OS X apps.
Stars: ✭ 44 (+109.52%)
Mutual labels:  promise

p-cache

Decorator to memoize the results of async functions via lru-cache.

NPM Build Status JavaScript Style Guide

Features

  • Uses lru-cache for caching impl
  • Uses object-hash for implicit cache key derivation from function args
  • Thoroughly tested in production

Install

npm install --save p-cache

Usage

const request = require('request-promise-native')

const pCache = require('p-cache')({
  label: 'test-service',
  // pass args to lru-cache here
  max: 1000
})

// returns an async function which gets the given url, with the results being 
// cached via lru-cache up to 1000 urls
module.exports = pCache(async (url) => {
  return request(url)
})

API

function pCache(opts)

Returns a function decorator that will wrap calls to the target function in an lru-cache instance defined by these opts.

  • opts - object, optional
  • opts.label - string, optional label to use for displaying cache hits and misses
  • opts.log - function, optional function to use for displaying cache hits and misses (default: console.log)

Note all unrecognized options are passed onto lru-cache

  • opts.max - number, optional passed onto lru-cache
  • opts.maxAge - number, optional passed onto lru-cache
  • opts.length - function, optional passed onto lru-cache
  • opts.dispose - function, optional passed onto lru-cache
  • opts.stale - boolean, optional passed onto lru-cache
  • opts.noDisposeOnSet - boolean, optional passed onto lru-cache

pCache(opts) => Function<Promise>(async function(...args))

License

MIT Β© Travis Fischer

Support my OSS work by following me on twitter twitter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].