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

Introduce AMP Live List Cache Busting #25295

Merged
merged 22 commits into from
Nov 4, 2019
Merged

Introduce AMP Live List Cache Busting #25295

merged 22 commits into from
Nov 4, 2019

Conversation

kristoferbaxter
Copy link
Contributor

Implement AMP Live List Cache Busting based on an Origin Trial. The Google AMP Cache has a bug where frequently updated content will not cause the distributed cache copy to correctly respond with the most up to date version of the document.

This issue is being addressed by the wg-caching group, but this Origin Trial is for domains who need more granular cached responses before the change to the Google AMP Cache is deployed.

// AMP Caches do not always evict entries from their caches.
// This experiment adds a random identifier to reduce cache hits for enrolled documents.
'amp_random': String(
Math.floor(Math.random() * AMP_LIVE_LIST_MAX_RANDOM_NUMBER)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we decide to not go with the Date header approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Date header approach needs additional testing on older browsers where our polyfill is providing a stubbed Response object.

Given the timing for the fix, and the remedy on the Google AMP Cache – I instead opted for the more narrow fix for enrolled documents.

this.manager_.register(this.liveListId_, this);
});
return this.isExperimentEnabled_().then(enrolled => {
LiveListManager.forDoc(this.element, enrolled).then(manager => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will enrolled propagate to the LiveListManager constructor?

static forDoc(element) {
return /** @type {!Promise<!LiveListManager>} */ (getServicePromiseForDoc(
element,
SERVICE_ID
));
}

Maybe we should do this check in LiveListManager on the first register() call instead. You can get an element from liveList.element in that function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can refactor this way, will be a little bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved over, mind taking another look?

@jridgewell jridgewell changed the title 🔥 Introduce AMP Live List Cache Busting ✨ Introduce AMP Live List Cache Busting Oct 28, 2019
@kristoferbaxter kristoferbaxter changed the title ✨ Introduce AMP Live List Cache Busting Introduce AMP Live List Cache Busting Oct 29, 2019
extensions/amp-live-list/0.1/live-list-manager.js Outdated Show resolved Hide resolved
'amp_latest_update_time',
String(this.latestUpdateTime_)
);
const parameters = this.enrolledInAppendRandomExperiment_

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a race condition here but the poll interval probably masks it. Probably worth testing to see.

(this.enrolledInAppendRandomExperiment_ =
trials && trials.includes('amp-live-list-random'))
);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) This might need to be moved back (outside of the outer conditional) to address the case where ampdoc.isVisible() == false at the time register() is invoked. I think this could happen if a user switches to another tab immediately after opening an AMP page.

Yea this class's control flow is not the cleanest.

@nainar
Copy link
Contributor

nainar commented Nov 4, 2019

Hi @kristoferbaxter @choumx is there a reason this PR is held up? This was needed in prod by now.

@kristoferbaxter kristoferbaxter merged commit 0d52ea2 into ampproject:master Nov 4, 2019
@kristoferbaxter kristoferbaxter deleted the live-list-random branch November 4, 2019 20:55
erwinmombay pushed a commit that referenced this pull request Nov 4, 2019
* Use a random number as a URL parameter for live list refreshes
* JsonObject casting required
* Is a dict
* Add amp-live-list-random origin trial to gate adding a random identifier to each update of the live list
* Changes based on PR feedback
* Guard origin trial check in tri-state boolean
* Add dep-check allowance
* moved dep-check to correct segment
* Only check for origin trial if the list is enabled
caroqliu added a commit that referenced this pull request Dec 5, 2019
caroqliu added a commit that referenced this pull request Dec 6, 2019
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* Use a random number as a URL parameter for live list refreshes
* JsonObject casting required
* Is a dict
* Add amp-live-list-random origin trial to gate adding a random identifier to each update of the live list
* Changes based on PR feedback
* Guard origin trial check in tri-state boolean
* Add dep-check allowance
* moved dep-check to correct segment
* Only check for origin trial if the list is enabled
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants