Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lru-memoize

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lru-memoize

A utility to provide lru memoization for any js function

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-24.78%
Maintainers
1
Weekly downloads
 
Created
Source

lru-memoize

NPM Version NPM Downloads Build Status

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.

Keywords

FAQs

Package last updated on 21 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc