Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache function reference when it's a single argument #35

Merged
merged 13 commits into from May 14, 2019

Conversation

Projects
None yet
2 participants
@bfred-it
Copy link
Collaborator

commented May 9, 2019

Since the very first version, mem has a "cache if it's not a function AND not an object", which I don't understand because functions are can't be serialized via JSON.stringify

In short (unless I'm drunk 馃) I think mem should always use the ONE argument as key, unless it's a serializable object.

bfred-it added some commits May 9, 2019

@bfred-it bfred-it referenced this pull request May 9, 2019

Merged

Reliable merge box handlers #2019

1 of 2 tasks complete
Show resolved Hide resolved index.js Outdated
@sindresorhus

This comment has been minimized.

Copy link
Owner

commented May 13, 2019

I think the reason I didn't support functions is that the user can set their own cache, and it might be something that needs to serialize the value.

Clarify condition further
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
@bfred-it

This comment has been minimized.

Copy link
Collaborator Author

commented May 13, 2019

and it might be something that needs to serialize the value.

In that case they can also set cacheKey, since it goes hand in hand with cache's key-ing mechanism.

bfred-it added some commits May 13, 2019

@sindresorhus

This comment has been minimized.

Copy link
Owner

commented May 13, 2019

In that case they can also set cacheKey, since it goes hand in hand with cache's key-ing mechanism.

I agree. Can you add a note about that in the readme? Just so we're clear about how it works. It might not be obvious to everyone that we cache the function reference too.

And https://github.com/sindresorhus/mem/blob/master/index.d.ts

@bfred-it

This comment has been minimized.

Copy link
Collaborator Author

commented May 13, 2019

It might not be obvious to everyone that we cache the function reference too.

Why would it be otherwise? I think at most we could mention that objects and multiple arguments are cached by value.

Show resolved Hide resolved readme.md Outdated

bfred-it added some commits May 13, 2019

Show resolved Hide resolved readme.md Outdated
Show resolved Hide resolved readme.md

@sindresorhus sindresorhus changed the title Cache functions as single argument Cache function reference when it's a single argument May 14, 2019

@sindresorhus sindresorhus merged commit 10f13c0 into sindresorhus:master May 14, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bfred-it

This comment has been minimized.

Copy link
Collaborator Author

commented May 15, 2019

Will you release this as a patch or are you waiting for #36 to release a major?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.