Interested in what you mean by annotating the page after caching it, do you have any more info on this?
An extra AJAX request grabs the users logged in status, CSRF token and similar data as JSON and then modifies the page so the user sees what they expect (a logout button, a comment form, etc).