anywhichway / nano-memoize

Faster than fast, smaller than micro ... a nano speed and size (780 Brotili bytes) memoize for single and multiple argument functions.
MIT License
212 stars 12 forks source link

clearing cache with max age #63

Closed darkship closed 12 months ago

darkship commented 12 months ago

Hello,

I'm using your lib like this:

const memo = nanomemoize(fn, { maxAge: 7_200_000 })

memo()
...
memo.clear()

While calling memo.clear() clears the cache, the setTimeout is not cleared and the process hangs.

anywhichway commented 12 months ago

Thanks, I will look into it over the next couple of days.


From: Thomas @.> Sent: Thursday, November 16, 2023 8:59:23 AM To: anywhichway/nano-memoize @.> Cc: Subscribed @.***> Subject: [anywhichway/nano-memoize] clearing cache with max age (Issue #63)

Hello,

I'm using your lib like this:

const memo = nanomemoize(fn, { maxAge: 7_200_000 })

memo() ... memo.clear()

While calling memo.clear() clears the cache, the setTimeouthttps://github.com/anywhichway/nano-memoize/blob/ca71d163db33fc894584133d3dc942cfb404f382/src/index.js#L44C46-L44C46 is not cleared and the process hangs.

— Reply to this email directly, view it on GitHubhttps://github.com/anywhichway/nano-memoize/issues/63, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABF2US2AMSF3ZU3LOY2GA5LYEZA6XAVCNFSM6AAAAAA7OPMVPCVHI2DSMVQWIX3LMV43ASLTON2WKOZRHE4TOMZRHE2TMMA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

anywhichway commented 12 months ago

I added the timeout clear and published as 3.0.16. I did not write a unit test to check this (since I am currently out sailing). However, you could test. All existing unit tests pass.

darkship commented 12 months ago

works