All Projects → feross → memo-async-lru

feross / memo-async-lru

Licence: MIT license
Memoize Node.js style callback-last functions, using an in-memory LRU store

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to memo-async-lru

disk-lru-cache
💾 Disk LRU cache with persisted journal
Stars: ✭ 21 (+23.53%)
Mutual labels:  lru, lru-cache
LruClockCache
A low-latency LRU approximation cache in C++ using CLOCK second-chance algorithm. Multi level cache too. Up to 2.5 billion lookups per second.
Stars: ✭ 35 (+105.88%)
Mutual labels:  lru, lru-cache
gocache
High performance and lightweight in-memory cache library with LRU and FIFO support as well as memory-usage-based-eviction
Stars: ✭ 15 (-11.76%)
Mutual labels:  lru, lru-cache
lru
LRU cache using go generics
Stars: ✭ 108 (+535.29%)
Mutual labels:  lru, lru-cache
cache
LRU-based cache package for Go.
Stars: ✭ 25 (+47.06%)
Mutual labels:  lru, lru-cache
go-cache-benchmark
Cache benchmark for Golang
Stars: ✭ 47 (+176.47%)
Mutual labels:  lru, lru-cache
hyperlru
Tiny & Fast LRU Implementation as possible.
Stars: ✭ 34 (+100%)
Mutual labels:  lru, lru-cache
golib
Open version of common golang libraries useful to many projects.
Stars: ✭ 47 (+176.47%)
Mutual labels:  lru, lru-cache
Olric
Distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
Stars: ✭ 2,067 (+12058.82%)
Mutual labels:  lru, lru-cache
GoCache
A simplest Cache Server based on LRU implementation written in Go
Stars: ✭ 15 (-11.76%)
Mutual labels:  lru-cache
react-shortcut
Convenient React component that detects if the given key combination is pressed, and triggers a callback
Stars: ✭ 16 (-5.88%)
Mutual labels:  callback
Algorithm-Implementation
This is our effort to collect the best implementations to tough algorithms. All codes are written in c++.
Stars: ✭ 16 (-5.88%)
Mutual labels:  lru-cache
ruling
Stateless rule engine
Stars: ✭ 19 (+11.76%)
Mutual labels:  callback
prophetjs
Vanilla JS library to display toast messages.
Stars: ✭ 31 (+82.35%)
Mutual labels:  callback
cacheify
Browserify transform wrapper that caches the transforms between runs to improve performance
Stars: ✭ 30 (+76.47%)
Mutual labels:  browserify
vk-callback-bot
Бот для сообществ VK на основе CallBack. Взаимодействие с клавиатурой, загрузка файлов.
Stars: ✭ 21 (+23.53%)
Mutual labels:  callback
globify
Run browserify and watchify with globs - even on Windows!
Stars: ✭ 16 (-5.88%)
Mutual labels:  browserify
browserify-aes
aes, for browserify
Stars: ✭ 56 (+229.41%)
Mutual labels:  browserify
WHMCS-JSJ-API-Pay-Gateway
WHMCS 财务系统对接金莎云免签支付API(你们怎么用,与我无瓜好吧:)
Stars: ✭ 58 (+241.18%)
Mutual labels:  callback
browserify-bower
A browserify plugin, to enable you use bower components just like node modules
Stars: ✭ 20 (+17.65%)
Mutual labels:  browserify

memo-async-lru travis npm downloads javascript style guide

Memoize Node.js style callback-last functions, using an in-memory LRU store

Also works in the browser with browserify!

install

npm install memo-async-lru

usage

const memo = require('memo-async-lru')

function fn (arg, cb) {
  t.equal(arg, 'foo')
  cb(null, 'bar')
}

const memoFn = memo(fn)

memoFn('foo', (err, result) => {
  console.log(result) // prints 'bar'

  memoFn('foo', (err, result) => {
    console.log(result) // prints 'bar', cached, does not call fn()
  })
})

API

memo(fn, [opts])

Memoize the given function fn, using async-lru, a simple async LRU cache supporting O(1) set, get and eviction of old keys.

The function must be a Node.js style function, where the last argument is a callback.

function(key: Object, [...], fetch: function(err: Error, value: Object))

So, if you were to do:

const readFile = memo(fs.readFile)
readFile('file.txt', fn)
readFile('file.txt', fn) // <-- this uses the cache

The file would only be read from disk once, it's value cached, and returned anytime the first argument is 'file.txt'.

Repeated calls to the function with the same first argument will return a cached value, rather than re-fetch the data.

Optionally, an opts parameter can be specified with the following properties: Optional options:

{
  max: maxElementsToStore,
  maxAge: maxAgeInMilliseconds
}

If you pass max, items will be evicted if the cache is storing more than max items. If you pass maxAge, items will be evicted if they are older than maxAge when you access them.

license

MIT. Copyright (c) Feross Aboukhadijeh.

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].