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

_isResponseDateFresh store with service time ; but get with local time? #1714

Closed
wxungang opened this issue Oct 17, 2018 · 3 comments
Closed
Labels
Needs More Info Waiting on additional information from the community.

Comments

@wxungang
Copy link

packages/workbox-cache-expiration/plugin.mjs

  _isResponseDateFresh(cachedResponse) {
    if (!this._maxAgeSeconds) {
      // We aren't expiring by age, so return true, it's fresh
      return true;
    }

    // Check if the 'date' header will suffice a quick expiration check.
    // See https://github.com/GoogleChromeLabs/sw-toolbox/issues/164 for
    // discussion.
    const dateHeaderTimestamp = this._getDateHeaderTimestamp(cachedResponse);
    if (dateHeaderTimestamp === null) {
      // Unable to parse date, so assume it's fresh.
      return true;
    }

    // If we have a valid headerTime, then our response is fresh iff the
    // headerTime plus maxAgeSeconds is greater than the current time.
    const now = Date.now();
   //todo:  if local time is later then service time?
    return dateHeaderTimestamp >= now - (this._maxAgeSeconds * 1000);
  }

question:
//todo: if local time is later then service time?

const now = Date.now();
return dateHeaderTimestamp >= now - (this._maxAgeSeconds * 1000);
@EvsChen
Copy link

EvsChen commented Oct 18, 2018

Hi @wxungang. Here is my naive understanding.
If you're referring to time zone by "local time later than service time", both Date header and Date.now() are in UTC. They will return the same number no matter which time zone you're in.
Refer to Headers/Date and Date.now() for details on Date.
If you're not talking about time zone, pls further clarify your problem.

@wxungang
Copy link
Author

wxungang commented Oct 19, 2018

@EvsChen not about time zone 。Time is out of sync between local and server in the same time zone!

we have set maxAgeSeconds:5*60 (5min)。
but the local time(now) - server time (dateHeaderTimestamp) > maxAgeSeconds。
so the response expired always

@jadjoubran
Copy link
Collaborator

@wxungang have you tested that this is actually what's happening?
Because I don't think the timezone on your server matters as the time workbox is comparing against the time the document was received and as @EvsChen mentioned everything is in UTC.

Feel free to post your configuration (the service worker code that uses maxAgeSeconds) so that I can check what's wrong

@jadjoubran jadjoubran added the Needs More Info Waiting on additional information from the community. label Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info Waiting on additional information from the community.
Projects
None yet
Development

No branches or pull requests

4 participants