1.0.1 • Published 5 months ago

memoize-me v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

memoize-me

A simple and efficient utility for converting any function into a memoized function, caching results for repeated calls with the same arguments.

Installation

npm install memoize-me

Usage

const memoize = require('memoize-me');

// Your original function to be memoized
const expensiveOperation = (param) => {
    // ... expensive computation ...
    return result;
};

// Memoize the function
const memoizedExpensiveOperation = memoize(expensiveOperation);

// Now use memoized function as usual
const result1 = memoizedExpensiveOperation('param1');
const result2 = memoizedExpensiveOperation('param1'); // Result retrieved from cache

// ...

API

memoize(fn)

fn (Function): The function to be memoized.

Returns

(Function): The memoized function.

How it Works

The memoize function utilizes a caching mechanism to store the results of previous function calls. If the same set of arguments is provided to the memoized function again, it retrieves the result from the cache instead of re-executing the original function. This can significantly improve performance for functions with expensive computations.

Example

const memoize = require('memoize-me');

const add = (a, b) => {
    console.log('Executing expensive computation...');
    return a + b;
};

const memoizedAdd = memoize(add);

console.log(memoizedAdd(2, 3)); // Executes expensive computation and returns 5
console.log(memoizedAdd(2, 3)); // Returns 5 from cache, without re-executing the expensive computation

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Feel free to customize it further based on your project's specific details.

1.0.1

5 months ago

1.0.0

5 months ago