Skip to content

Shallow compare function arguments for memoization.

Notifications You must be signed in to change notification settings

blackChef/shallowMemoize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShallowMemoize

Memoization with ability to set cache size and use shallow comparison.

Usage

import memoize from 'shallow-memoize'

let memoizeOptions = {
  cacheSize: 1, // size of cache, should be greater than 0. Default is Infinity.
  useShallowCompare: true, // whether shallow compare should be used. Default is false.
};

let add = memoize(function(a, b) {
  return a.val + b.val;
}, memoizeOptions);

add({ val: 5 }, { val: 5 });
add({ val: 5 }, { val: 5 }); // cache hit

add({ val: 3 }, { val: 3 });
add({ val: 3 }, { val: 3 }); // cache hit

add({ val: 5 }, { val: 5 }); // no cache, because cache size is 1

About

Shallow compare function arguments for memoization.

Resources

Stars

Watchers

Forks

Packages

No packages published