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

Cache#isExpired is always false with default EXPIRES_IN_. #84

Merged
merged 1 commit into from
Sep 4, 2013

Conversation

robhanlon22
Copy link

https://github.com/google/google-api-nodejs-client/blob/3d40484947a45b6eca73ef68f3c5a9e545aa250f/lib/cache.js#L94

new Date(fs.statSync(path).mtime).getTime() will return a number on the order of 1377737486000 (taken from a recently modified file on my filesystem). Cache.EXPIRES_IN_ is, by default, 300000. Thus, only files that were modified within 299999 milliseconds of the epoch will ever be considered expired. The correct logic is as follows:

Cache.prototype.isExpired = function(path) {
  var expiresIn = this.opts.expiresIn || Cache.EXPIRES_IN_;
  return Date.now() - new Date(fs.statSync(path).mtime).getTime() > expiresIn;
};

Not sure about test practices, etc, but I've attached some code with this in place.

rakyll pushed a commit that referenced this pull request Sep 4, 2013
Cache#isExpired is always false with default EXPIRES_IN_.
@rakyll rakyll merged commit 7feb348 into googleapis:master Sep 4, 2013
@rakyll
Copy link
Contributor

rakyll commented Sep 4, 2013

I couldn't get how the original code passed the code review :) Good catch, thanks.

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.

2 participants