-
Notifications
You must be signed in to change notification settings - Fork 1
Implement HTTP cache invalidation #23
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @westonruter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the existing cache invalidation mechanism by extending its scope to cover HTTP cache, in addition to the browser's back/forward cache (bfcache). The core change involves a client-side check that compares a session token embedded in the HTML with the current user's session cookie, ensuring that stale authenticated pages are reloaded upon restoration from any cache.
Highlights
- HTTP Cache Invalidation: Implemented a client-side mechanism to invalidate pages restored from HTTP cache by comparing an
initialSessionToken(passed from PHP in the HTML) with the current user's session cookie. If they don't match, the page is reloaded. - Enhanced Page Reload Logic: Introduced a dedicated
invalidateCache()JavaScript function that visually clears the page content and forces a full reload when a session token mismatch is detected. - Internationalized Debugging & Feedback: Added internationalized strings for console logging and user feedback during the cache invalidation process.
- Infinite Reload Prevention: Incorporated a query parameter (
nocache_bfcache_invalidated_page_reloaded) to prevent scenarios where a page might repeatedly be deemed stale and trigger continuous reloads.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively implements HTTP cache invalidation by passing an initial session token in the HTML and comparing it against the session token cookie on page load. The logic is sound, and it includes important safeguards like protection against infinite reloads.
My review highlights a minor typo in a translatable string and suggests a safer approach for DOM manipulation during cache invalidation to improve robustness. Overall, the changes are well-structured and successfully achieve the PR's goal.
| document.body.style.opacity = '0.0'; | ||
|
|
||
| // Immediately clear out the contents of the page since otherwise the authenticated content will appear while the page reloads. | ||
| document.documentElement.innerHTML = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using document.documentElement.innerHTML = '' is very aggressive as it clears the entire <html> element's content, including the <head> and the currently executing script. This can lead to unpredictable behavior and is generally unsafe. It also removes the <body> element on which you just set the opacity, so a new <body> is created by the browser without this style.
A safer alternative is to clear only the <body>. This achieves the goal of removing visible stale content without being overly destructive.
| document.documentElement.innerHTML = ''; | |
| document.body.innerHTML = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gemini-code-assist Complete destruction is intended, as it needs to also remove any stylesheets or content in the HEAD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification, @westonruter. Your explanation makes perfect sense. If the intent is indeed to perform a complete destruction of the page's loaded content, including stylesheets and other elements within the <head> that might persist or affect the display before a full reload, then document.documentElement.innerHTML = '' is the correct and most effective approach to achieve that level of invalidation. My initial suggestion was based on a more common scenario of clearing only visible body content, but your requirement for comprehensive removal necessitates this more aggressive method.
No description provided.