dcousens / sru.js

A dead simple, performant somewhat-recently-used cache, busts after N insertions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sru

build status Version

A dead simple, in memory, somewhat-recently-used cache.

O(1) insertion, retrieval and deletion.

ESNext alternative

If you can, don't use this library. Use an ESNext WeakMap instead.

Examples

function cubed (x) {
  return x * x * x
}

let sru = require('sru')
let cache = sru(100)

console.log(cache(8, cubed), 512)
console.log(cache(8, cubed), 512) // cubed was not called this time

License MIT

About

A dead simple, performant somewhat-recently-used cache, busts after N insertions.

License:MIT License


Languages

Language:JavaScript 100.0%