-
Notifications
You must be signed in to change notification settings - Fork 48
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
Caching requested data #79
Comments
Hi Andrés, thanks for your compliments! CachingI think the easiest way to provide caching would be to make axios do it for you. Getting the
|
Here is an ugly way how you could get the params in the You could create a new property in the store and save it in the beforeRequest. Then you could call it in the onSuccess fn. It's not pretty but it works. Example (didn't test it) {
beforeRequest: (state, { params, data }) => {
state.year = params.year
},
onSuccess: (state, payload, axios) => {
const year = state.year
state.yearInfo[year] = payload.data
}
} |
Thanks for the quick replies! Is it possible to avoid the request from happening from inside Going back to the other alternative... I took a look at both axios caching libs. But I'm a bit worried about how to invalidate some cached items when the user modifies server data.
|
This is not possible at the moment. If you use https://github.com/kuitos/axios-extensions#cacheadapterenhancer this shouldn't be a problem because the request will only be sent to the server if the cache expires or the response isn't cached yet.
Yep, race condition. :( Caching is something I didn't think about during the development of vuex-rest-api. Currently I'm developing version 3 of vuex-rest-api. I'll consider your issues and try to solve it with a new API. Unfortunately I don't think I will change this in the current version. I'm sorry. |
I feel I would have a better control over the cache doing it at vuex-rest-api level. But since it lacks some features needed for it, I guess I'll try axios-extensions, forcing data reload just after data modification.
I understand, no problem. And thanks for considering it for v3. Feel free to close this issue if you feel so. |
I think so, too. :)
Anytime! Little note: I don't know when I'll release v3. Approximately in 2-3 months without guarantee! Feel free to open a new issue if you have any questions. |
I've added the |
Wow! Thank you! =D
|
Hello! And thanks for creating and maintaining this great lib!
I've read the README and checked the issues, but couldn't find a way to "cache" the data to avoid requesting it again.
For example, my view requests the data. Then I route to another view, and later I come back. The data will be requested again.
One option would be to check in the component, before requesting the data, to see if the data is already there. But instead of each component doing the check, it would be better if the store did it. Maybe the
beforeRequest
can be used for this?And sometimes the same endpoint can return data about different elements. I try to store them in an object, like the code bellow. But then, how can I get the element "id" in the
onSuccess
, so I can store it in the object?Component
Store
I saw something about
axios
being able to cache GET requests. Would it be a better solution for this issue?The text was updated successfully, but these errors were encountered: