lru-memoize

1.1.0last stable release 6 years ago
Complexity Score
Low
Open Issues
N/A
Dependent Projects
46
Weekly Downloadsglobal
12,974

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

lru-memoize

lru-memoize is a utility to provide simple memoization for any pure javascript function, using an LRU cache that prioritizes the most recently accessed values, and discards the “least recently used” (LRU) items when the size limit is reached. If your function has side effects or relies on some external state to generate its result, it should not be memoized.

Installation

npm install --save lru-memoize

Usage

Let’s look at an example where we want to memoize a function that multiplies three numbers together, and we want to keep the last ten arguments -> value mappings in memory.

ES5

var memoize = require('lru-memoize');

var multiply = function(a, b, c) {
  return a * b * c;
}

multiply = memoize(10)(multiply);

module.exports = multiply;

ES6

import memoize from 'lru-memoize';

let multiply = (a, b, c) => a * b * c;

multiply = memoize(10)(multiply);

export default multiply;

API

memoize(limit:Integer?, equals:Function?, deepObjects:Boolean?)

Returns (Function) => Function.

-limit : Integer [optional]

The number of arguments -> value mappings to keep in memory. Defaults to 1.

-equals : Function [optional]

A function to compare two values for equality. Defaults to ===.

-deepObjects : Boolean [optional]

Whether or not to perform a deep equals on Object values. Defaults to false.

Dependencies

No runtime dependency information found for this package.

CVE IssuesActive
0
Scorecards Score
2.30
Test Coverage
No Data
Follows Semver
Yes
Github Stars
317
Dependenciestotal
37
DependenciesOutdated
13
DependenciesDeprecated
3
Threat Modelling
No Data
Repo Audits
No Data

Learn how to distribute lru-memoize in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install lru-memoize
Processing...
Done

6 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.