medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.73k stars 61 forks source link

WeakMap mode ignores maxAge #79

Closed vprus closed 7 years ago

vprus commented 7 years ago

It appears that if I require(memoizee/weak), then it does not respect maxAge option. The following program prints the same value all over:

const Promise = require('bluebird')
const memoize = require('memoizee/weak');

let thing = {}

let count = 0;
async function whatever(thing) {
    await Promise.delay(500)
    return count++;
}

const memoized = memoize(whatever, {
    promise: true,
    primitive: true,
    maxAge: 1
})

async function test() {
    for (let i = 0; i < 10; ++i) {
        console.log(memoized(thing))
        await Promise.delay(1000)
    }
}

test().then(() => console.log(done), (err) => console.log(err))

If I add


require('memoizee/ext/max-age')
``

then it works as expected. It looks that the default non-weak case requires all extensions internally, while the weak one does not.
medikoo commented 7 years ago

Great thanks for reporting, fixed with f29a97b published as v0.4.5

vprus commented 7 years ago

Thanks, I can confirm that v0.4.5 works fine.