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

Adding Option to give users finer control of what results get cached. #17

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

ygonzal6
Copy link
Contributor

Background information
Our team is currently using the Funnel to cache network request.
It was noticed that error responses are also cached, which is less then ideal.

Implementation summary
Add an Option to the Funnel constructor that takes in a predicate that will return true if a result
should be cached and false otherwise. The predicate will have the following signature func(interface{}, error)bool
which matches the return value from the execute.
With this solutions user can chose to have complete control of what results get cached or whether to use the default behavior.

Before & after
Before:
No option to control what gets cached.

After:
func WithShouldCachePredicate(p func(interface{}, error) bool) Option {
return func(cfg *Config) {
cfg.shouldCache = p
}
}

Risk mitigation
Unit test has been added to cover the new Option

Ticket
https://jira.mailchimp.com/browse/DATABRIDGE-1003

@ollana ollana self-requested a review March 27, 2023 11:24
Copy link
Collaborator

@ollana ollana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you for the contribution!
do you mind adding a small usage example to the documentation?

@ollana ollana merged commit a12203b into intuit:master Mar 27, 2023
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.

2 participants