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

moize

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moize

Blazing fast memoization based on all parameters passed

  • 6.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
240K
decreased by-0.76%
Maintainers
2
Weekly downloads
 
Created

What is moize?

moize is a powerful memoization library for JavaScript that helps optimize performance by caching the results of function calls. It supports various features such as custom cache handling, expiration, and serialization.

What are moize's main functionalities?

Basic Memoization

This feature allows you to memoize a function so that its results are cached based on the arguments provided. Subsequent calls with the same arguments will return the cached result.

const moize = require('moize');

const add = (a, b) => a + b;
const memoizedAdd = moize(add);

console.log(memoizedAdd(1, 2)); // 3
console.log(memoizedAdd(1, 2)); // 3, retrieved from cache

Custom Cache Handling

This feature allows you to use a custom cache implementation. You can specify the maximum size of the cache and other options.

const moize = require('moize');

const customCache = new Map();
const memoizedFunction = moize({
  maxSize: 5,
  isPromise: false,
  cache: {
    create: () => customCache
  }
})(functionToMemoize);

memoizedFunction(args);

Expiration

This feature allows you to set an expiration time for the cached results. After the specified time, the cache will be invalidated.

const moize = require('moize');

const memoizedFunction = moize({
  maxAge: 1000 // cache expires after 1 second
})(functionToMemoize);

memoizedFunction(args);

Serialization

This feature allows you to serialize the arguments before caching. This is useful for functions that take complex objects as arguments.

const moize = require('moize');

const memoizedFunction = moize({
  serializer: (args) => JSON.stringify(args)
})(functionToMemoize);

memoizedFunction(args);

Other packages similar to moize

Keywords

FAQs

Package last updated on 08 May 2023

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