medikoo / memoizee

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

Memoizing a function without arguments #125

Closed jkantr closed 3 years ago

jkantr commented 3 years ago

I would like to memoize a function that has no arguments. "Why would you want to do that?", I hear you cry. Simply, it's an async function that returns a promise that resolves to undefined. Everything that happens in the function is a side effect. I want to throttle it using memoize and the maxAge property, so all attempts in between the cache maxAge just get dropped (have the promise resolving to undefined be returned, but none of the side effects happening).

I've tried cheeky attempts like setting length: 0 (I didn't... really expect it to work lol), but I was just wondering if there's support for this use case that I'm missing. Otherwise I understand it's likely out of scope, thanks.

jkantr commented 3 years ago

Closing thread, this behavior seems to already work by default. There was some event-driven stuff in my code that was recreating the memoized wrapper, my bad.