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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support options.keyArgs to complement options.makeCacheKey. #65

Merged
merged 1 commit into from
May 12, 2020

Conversation

benjamn
Copy link
Owner

@benjamn benjamn commented May 12, 2020

This optional function takes the raw arguments passed to an OptimisticFunctionWrapper and simplifies/filters/reduces them down to an array of arguments sufficient to identify the cache result. This simplified array of arguments is then passed to options.makeCacheKey (or defaultMakeCacheKey if no options.makeCacheKey was provided).

The resulting array serves as the arguments list for any function that only needs to compute a cache key (and thus does not need the full raw arguments), such as wrapper.dirty and options.makeCacheKey. This makes it possible to dirty a cached function using less information than would be required to call it properly, which is useful in some cases.

In some sense, options.keyArgs and options.makeCacheKey divide up the work of computing cache keys from raw arguments. Both functions are optional, and any combination of the two that satisfies the type system is allowed. If the sequence of arguments returned by options.keyArgs can be passed directly to defaultMakeCacheKey, you may not need to define a custom options.makeCacheKey function anymore.

This optional function takes the raw arguments passed to an
OptimisticFunctionWrapper and simplifies/filters/reduces them down to an
array of arguments sufficient to identify the cache result. This
simplified array of arguments is then passed to options.makeCacheKey (or
defaultMakeCacheKey if no options.makeCacheKey was provided).

The returned array serves as the arguments list for any function that only
needs to compute a cache key (and thus does not need the full raw
arguments), such as wrapper.dirty and options.makeCacheKey. This makes it
possible to dirty a cached function using less information than would be
required to call it properly, which is useful in some cases.

In some sense, options.keyArgs and options.makeCacheKey divide up the work
of computing cache keys from raw arguments. Both functions are optional,
and any combination of the two that satisfies the type system is allowed.
If the sequence of arguments returned by options.keyArgs can be passed
directly to defaultMakeCacheKey, you may not need to define a custom
options.makeCacheKey function anymore.
@benjamn benjamn merged commit 85ee880 into master May 12, 2020
@benjamn benjamn deleted the options.keyArgs branch May 12, 2020 18:37
benjamn added a commit that referenced this pull request May 12, 2020
The minor version bump is due to non-breaking new features introduced by
PRs #65 (options.keyArgs) and #66 (wrapper.peek).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant