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

feat: Allow using the cache when triggering requests manually #20

Merged
merged 1 commit into from
Jul 18, 2019

Conversation

simoneb
Copy link
Owner

@simoneb simoneb commented Jul 17, 2019

Closes #19

}

interface Options {
manual: boolean
}

interface RefetchOptions {
useCache: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in the Issue, I think it would be better to allow a user to choose to use caching for the standard useAxios behaviour or refetch. If that was decision was made, useCache could move to the Options interface. As it stands though, having useCache in this new RefetchOptions interface works.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not convinced we should have that option there to be honest. I mean the hook will execute whenever the component renders, meaning that having that option there and choosing to not use the cache will trigger a request whenever the component re-renders, which I see no reason why anybody would want to do. I think we should stick to the option being provided to the "refetch" function, with cache off by default, as in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

"I see no reason why anybody would want to do" - I guess it depends how volatile the data is on the server. TBH I am happy with what you have proposed so I reckon you should go ahead and merge the PR.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not really, because you shouldn't rely on the frequency with which a component renders to carry out any application logic. That should be transparent for the developer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, fair enough. It's just that cache invalidation is always a nightmare! Good work @simoneb

Copy link
Owner Author

Choose a reason for hiding this comment

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

I know. If you've used Apollo you know that it's really not easy to implement and use.

Copy link
Contributor

@8enSmith 8enSmith left a comment

Choose a reason for hiding this comment

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

One comment. Other than that looks good.

@simoneb simoneb merged commit 8b4ad9a into master Jul 18, 2019
@simoneb simoneb deleted the manual-with-cache branch July 18, 2019 14:14
@simoneb
Copy link
Owner Author

simoneb commented Jul 18, 2019

Released in 1.2.0

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.

Feature request: Enable caching for manual requests
2 participants