Skip to content

Unit test needed to prevent #14 regression #45

Closed

Description

@runemadsen

Hi there

Awesome library. I have one question though:

It seems like you're appending random query strings to the end of every API call, probably in order to make sure you get a non-cached response on every call.

However, the Gihub API implements a pretty smart HTTP caching, that is being ignored with this library. For people using it, it means that the rate-limit will get used much faster, and apps will try to reload content that is not updated.

Here's an example of what I mean:

/* Using JQuery
____________________________________________ */

$.ajax({
  url:"https://user:pass@api.github.com/repos/user/repo",
  success: function(data) { console.log(data) }
});
// --> response 200 with content

$.ajax({
  url:"https://user:pass@api.github.com/repos/user/repo",
  success: function(data) { console.log(data) }
});
// --> if called again within 60 seconds this call will never be made, 
//      as the Github API has HTTP cache of 60 seconds. If after 
//      60 seconds and data is not updated, it returns an empty 
//      304 not modified, which is much faster

/* Using github.js
____________________________________________ */

var github = new Github({
  username: "user",
  password: "pass",
  auth: "basic"
});
var repo = github.getRepo(user, repo);

repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content

repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content, no caching

repo.show(function(err, repo) { console.log(repo) });
// --> response 200 with content, no caching

I saw that you have "implemented smart caching" in a commit, so I'm not sure exactly what's going on. How is this library caching stuff?

Activity

  1. w35l3y commented on May 21, 2014

    @w35l3y

    👍

    I miss it too for the same reason

  2. aendra-rininsland commented on Oct 17, 2015

    @aendra-rininsland
    Member

    Seriously? Lulz @ "smart caching"...

    This should be fixed and the whole random number thing removed. Marking as P2 bug for 0.10.7.

  3. added this to the v0.10.7 milestone on Oct 17, 2015
  4. changed the title [-]Disables HTTP Caching[/-] [+]Fix HTTP Caching[/+] on Oct 17, 2015
  5. aendra-rininsland commented on Oct 19, 2015

    @aendra-rininsland
    Member

    I've removed the cache buster from _request. This means that it should fall back to XMLHttpRequest's caching layer.

    Edit: Apparently XMLHttpRequest only caches responses in the browser. This probably needs to be implemented in the lib for NodeJS. Reopening...

  6. aendra-rininsland commented on Oct 19, 2015

    @aendra-rininsland
    Member

    Actually, this is now resolved — GitHub only sends a 304 and no body if you send a conditional header. Therefore there's no reason to add a cache buster to the URL (other than to get around the browser's caching; if anything, the cache buster should be added via an option, though given I am currently unsure how to do that, am leaving it be for the moment).

    The question is, how best to deal with said-headers? I really, really don't feel like writing some caching noise right now, so am closing this and reopening #53. Please direct all conversation re: conditional headers and caching there. Thanks!

  7. w35l3y commented on Oct 20, 2015

    @w35l3y

    Just to mention getTime was proposed by the author to fix #14
    I haven't tested it to verify whether removing it would reopen #14

  8. aendra-rininsland commented on Oct 21, 2015

    @aendra-rininsland
    Member

    @w35l3y Yeah, I was considering that. What's really needed is a unit test for #14. Reopening, renaming, adding label.

  9. changed the title [-]Fix HTTP Caching[/-] [+]Unit test needed to prevent #14 regression[/+] on Oct 21, 2015
  10. aendra-rininsland commented on Oct 21, 2015

    @aendra-rininsland
    Member

    Hm. I've added a new unit test, but I don't know whether it will actually test what I'm wanting simply because wrapping the tests in Browserify will cause it to use node-xmlhttprequest when we're wanting to test it using the browser's version of XHR. This might have to be delayed until we migrate the test architecture to Karma or something.

  11. AurelioDeRosa commented on Oct 22, 2015

    @AurelioDeRosa
    Member

    I'd say that since this is a library mainly used client-side, it's fine for now to have a sure fix for browsers. This should be enough until we have a good plan for the new, shiny, improved version.

  12. added a commit that references this issue on Oct 23, 2015
    b4a99cf
  13. added a commit that references this issue on Oct 23, 2015
    78c8b78
  14. aendra-rininsland commented on Oct 23, 2015

    @aendra-rininsland
    Member

    I've made it so the library now adds the timestamp to the URL if being used in the browser, and have written a unit test that replicates #14. It won't ever fail if used via Tape because of no caching in NodeJS, but can act as a good regression test once we move to Mocha or whatevs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions