Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 1, 2024 via pnpm

memoize-one 6.0.0

A memoization library which only remembers the latest invocation
Package summary
Share
0
issues
1
license
1
MIT
Package created
6 Feb 2017
Version published
20 Oct 2021
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
memoize-one@6.0.0
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of memoize-one 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does memoize-one do?

"memoize-one" is a memoization library designed for JavaScript applications. It aims to provide a good performance boost to an application by caching the result of the most recent function invocation. This characteristic sets it apart from other memoization libraries: "memoize-one" only remembers the latest arguments and result, and does not use cache busting mechanisms like maxAge, maxSize, or exclusions. If the memoized function is called again with the same arguments as the last time, "memoize-one" will return the previously cached result, resulting in a potential performance boost. The library also provides additional features, such as ability to clear the cache and custom equality function support.

How do you use memoize-one?

To use "memoize-one", first install the package via npm or yarn.

# npm
npm install memoize-one --save

# yarn
yarn add memoize-one

Then, you can import it into your JavaScript files and use it to memoize your functions. Here's an example:

import memoizeOne from 'memoize-one';

const expensiveFunction = (arg1, arg2) => {
  // expensive computation here
  .......
  return result;
}

const memoizedExpensiveFunction = memoizeOne(expensiveFunction);

// Call the memoized function
var result1 = memoizedExpensiveFunction(arg1, arg2); 

// if called again with the same arguments, memoized result will be returned
// improving the performance

var result2 = memoizedExpensiveFunction(arg1, arg2);

The library also allows you to use a custom equality function, which determines whether the new arguments are equivalent to previous ones. Here's an example, using the lodash.isequal function:

import memoizeOne from 'memoize-one';
import isEqual from 'lodash.isequal';

const identity = (x) => x;

const memoized = memoizeOne(identity, isEqual);

The memoization cache can be manually cleared using the .clear() function that is attached to memoized functions:

const memoizedExpensiveFunction = memoizeOne(expensiveFunction);

memoizedExpensiveFunction(arg1, arg2); // calculate result and cache it
memoizedExpensiveFunction.clear(); // clear the cache

Where are the memoize-one docs?

For detailed documentation and additional usage examples of "memoize-one", you can check out the official GitHub repo. The repository includes explanations of how the library handles different types of function arguments and contexts, customization of the equality function, handling function properties, and more. You will also find performance comparisons and information about code health.