erikras / lru-memoize

A utility to provide LRU memoization for any js function
MIT License
316 stars 20 forks source link

Functions called with deeply equal arguments (and deepEqual=true) seemingly not being memoized #73

Closed tnrich closed 7 years ago

tnrich commented 8 years ago

Hey there @erikras,

Thanks for the great tool. I'm having an issue where calling my memoized function with deeply nested objects that are deeply equal and having the deepEqual option set to true still results in a new function call.

Here's an example of this happening:

var lruMemoize = require("lru-memoize")
function test(options) {
    console.log('HELLO WORLD');
    return 'hello'
}

var mTest = lruMemoize(1,undefined,true)(test)

mTest({
    a: {
        yup: 'nope'
    },
    b: {
        well: 'no'
    }
})
mTest({
    a: {
        yup: 'nope'
    },
    b: {
        well: 'no'
    }
})

In this case "Hello World" is output to the console twice, instead of just once.

Any help solving this would be appreciated. Thanks! Thomas

oculus42 commented 8 years ago

The way the config is handled, it doesn't handle the undefined value for the equal function. If you remove the undefined, this will work. It would be nice if it supported the undefined, as well.

erikras commented 7 years ago

Published fix in v1.0.2.