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

fast-memoize

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-memoize

Fastest memoization lib that supports N arguments

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-12.47%
Maintainers
1
Weekly downloads
 
Created

What is fast-memoize?

The fast-memoize npm package is a high-performance memoization library that caches the results of function calls, so that the result can be quickly retrieved when the function is called again with the same arguments. This can significantly improve performance for functions with expensive computations or I/O operations that are called repeatedly with the same inputs.

What are fast-memoize's main functionalities?

Simple memoization

This feature allows you to memoize a simple function like the Fibonacci sequence. The memoized version of the function will remember the results of previous calls and return the cached result when the same input occurs again.

const memoize = require('fast-memoize');
const fibonacci = n => (n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2));
const memoizedFibonacci = memoize(fibonacci);
console.log(memoizedFibonacci(10));

Custom cache

This feature allows you to provide a custom cache implementation. By default, fast-memoize uses a plain JavaScript object as a cache, but you can replace it with any other object that follows the Map interface, such as a Map instance.

const memoize = require('fast-memoize');
const myCache = new Map();
const memoizedFn = memoize(fn, { cache: { create: () => myCache } });

Custom serializer

This feature allows you to provide a custom serializer for the arguments of the memoized function. By default, fast-memoize uses a serializer that can handle primitives and object references, but with a custom serializer, you can extend this to handle more complex serialization scenarios.

const memoize = require('fast-memoize');
const jsonSerializer = { serialize: JSON.stringify };
const memoizedFn = memoize(fn, { serializer: jsonSerializer });

Custom strategy

This feature allows you to provide a custom memoization strategy. fast-memoize comes with a default strategy that works well for most cases, but you can implement your own strategy for more control over how memoization is applied.

const memoize = require('fast-memoize');
const customStrategy = require('my-custom-strategy');
const memoizedFn = memoize(fn, { strategy: customStrategy });

Other packages similar to fast-memoize

FAQs

Package last updated on 26 Jan 2017

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