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

fetch() caches previous responses, returns bad results #33

Open
kabirsikand opened this issue Oct 4, 2014 · 3 comments
Open

fetch() caches previous responses, returns bad results #33

kabirsikand opened this issue Oct 4, 2014 · 3 comments

Comments

@kabirsikand
Copy link

When an array is returned from a fetch() call, any consecutive fetch() calls use the same (cached) array as a response, overwrite it with any incoming indices, and returns the resulted array to the caller.
e.g.

some_link_resource.fetch() ->
network response: [ object1, object2, object3, object4 ]
fetch results: [ object1, object2, object3, object4 ]

some_other_link_resource.fetch() ->
network response: [ object5, object6 ]
fetch results: [ object5, object6, object3, object4 ]

some_third_link_resource.fetch() ->
network response: [ ]
fetch results: [ object5, object6, object3, object4 ]
@passy
Copy link
Contributor

passy commented Oct 4, 2014

See under the "Links" section: https://weluse.github.io/hyperagent/:

By default, fetch() only requests the resource once from the server and directly returns a promise on the cached result on successive calls. If you want to force a refresh from the server, you can set the force flag in an options object:

root.links['ht:users'].fetch().then(...);

// Enforce a refresh.
root.links['ht:users'].fetch({ force: true }).then(...);

@passy passy closed this as completed Oct 4, 2014
@kabirsikand
Copy link
Author

Even when a refresh is forced on the fetch call, the results are cached in the case of array results. The example I provided can be mimicked with the force option set below:

## should return 4 results
some_link_resource.fetch({force:true}) ->
network response: [ object1, object2, object3, object4 ]
fetch results: [ object1, object2, object3, object4 ]

## should return 2 results
some_other_link_resource.fetch({force:true}) ->
network response: [ object5, object6 ]
fetch results: [ object5, object6, object3, object4 ]

## should return an empty array
some_third_link_resource.fetch({force:true}) ->
network response: [ ]
fetch results: [ object5, object6, object3, object4 ]

Again, the fact that network calls are being sent out and received shows that the links should not be caching previous results, since the links are each separate calls, not successive calls on the same link resource. The {force:true} option need not even be set in this case.

However, in the case of pure object responses, the behavior is as expected.

some_object_link_resource.fetch({force:true}) ->
network response: { key1: object1, key2: object2, key3: object3 }
fetch results: { key1: object1, key2: object2, key3: object3 }

some_other_object_link_resource.fetch({force:true}) ->
network response: { key1: object1, key2: object2 }
fetch results: { key1: object1, key2: object2 }

some_third_object_link_resource.fetch({force:true}) ->
network response: { }
fetch results: { }

@kabirsikand
Copy link
Author

I suggest reopening this.

@passy passy reopened this Oct 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants