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

memoizerific

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoizerific

Fast, small, efficient JavaScript memoization lib to memoize JS functions

  • 1.11.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2M
decreased by-61.04%
Maintainers
1
Weekly downloads
 
Created

What is memoizerific?

memoizerific is a JavaScript library that provides a simple and efficient way to memoize functions. Memoization is a technique used to speed up function execution by caching the results of expensive function calls and returning the cached result when the same inputs occur again.

What are memoizerific's main functionalities?

Basic Memoization

This feature allows you to memoize a function with a specified cache size. In this example, the function adds two numbers and caches the result for up to 100 different input combinations.

const memoizerific = require('memoizerific');

const memoizedFunction = memoizerific(100)((a, b) => a + b);

console.log(memoizedFunction(1, 2)); // 3
console.log(memoizedFunction(1, 2)); // 3 (cached result)

Cache Size Limitation

This feature demonstrates how the cache size limitation works. When the cache exceeds the specified size, the oldest cached result is evicted.

const memoizerific = require('memoizerific');

const memoizedFunction = memoizerific(2)((a, b) => a + b);

memoizedFunction(1, 2); // Cache: {(1, 2): 3}
memoizedFunction(2, 3); // Cache: {(1, 2): 3, (2, 3): 5}
memoizedFunction(3, 4); // Cache: {(2, 3): 5, (3, 4): 7} (1, 2) is evicted

Function Argument Handling

This feature shows how memoizerific can handle functions with variable numbers of arguments. The function sums all its arguments and caches the result.

const memoizerific = require('memoizerific');

const memoizedFunction = memoizerific(100)((...args) => args.reduce((sum, val) => sum + val, 0));

console.log(memoizedFunction(1, 2, 3)); // 6
console.log(memoizedFunction(1, 2, 3)); // 6 (cached result)

Other packages similar to memoizerific

Keywords

FAQs

Package last updated on 23 Mar 2018

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