Pretty much every page of my website is dynamically generated. However they don't change that frequently (kinda similar to a forum page). So I'd like to cache them using a caching reverse proxy such as Squid, varnish or Nginx.
The problem is that for my logged-in users, each of them will see a personalized header saying "Welcome John Doe. Logout" on the upper right corner of the page (just like serverfault). While users who aren't logged in will see a header that says "Login" instead.
So basically even though every user will see the same page in general, they all slightly different version due to that personalized header.
Is there any way so that I can cache the "main" part of the page and serve it from cache while generate the personalized header dynamically for each individual user?
This must be a very common problem. How is it solved in general?