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

Modifying amplify.request return value also affects cached value #91

Open
cstigler opened this issue Oct 10, 2013 · 3 comments
Open

Modifying amplify.request return value also affects cached value #91

cstigler opened this issue Oct 10, 2013 · 3 comments
Labels

Comments

@cstigler
Copy link

Not sure if this is a bug, or more of a feature request, but I found this to be very unexpected behavior so I think it warrants documentation at the

I have a cacheable amplify request. It contains an array. In processing this array, I go through by arr.shift() and processing each value as it comes out.

When I call the request again, it pulls from the cache a response with an empty array -- because the array I was modifying was apparently the same one it stored.

I understand this could have some roadblocks to a complete fix -- amplify would have to deep copy the response, probably -- but it would be really helpful. At the very least this should be documented somewhere, since I was not expecting this and it was difficult to debug.

@dcneiner
Copy link
Contributor

I want to leave this open to be address in terms of a fix, but just wanted to provide a work around for you:

http://jsfiddle.net/5VMZc/1/

That shows it breaking. If you uncomment the overwrite to the custom cache, you will see it works. This will be the easiest way to include a fix for you vs. having to handle it on the receiving end of all your requests.

@cstigler
Copy link
Author

Thanks for the idea -- didn't even realize I could overwrite the caching function. I'm guessing for an actual solution, it would be easiest to just pull the direct responseText and parse that out as the cache to avoid having to implement a deep copy in the library. Or would just JSON stringify/parse work in this case?

@dcneiner
Copy link
Contributor

@cstigler It will probably depend on the browser speed. I am not sure which is faster JSON stringify/parse vs. deepClone. It might be close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants