Summary
As I'm looking on stackoverflow and around the net, I find that there is a general lack of good documentation on best practices for caching a high performance site that uses sessions. It would be helpful if we can share some ideas around some basic building blocks particularly around caching. For the purpose of this discussion, I'm avoiding memcache and focusing on the caching of static and pages that are fully generated.
So to set up the scenario, imagine a web server (say nginx), reverse proxy (say varnish), app server (whatever), db server (say mysql).
Anonymous
- Static items (gif/jpg etc.)
- Semi dynamic (js/css)
- Dynamic
Logged In
- Static
- Semi dynamic (js/css)
- Dynamic
Generally speaking, all of the Anon should be cacheable and most of Logged In (ignore dynamic, no ESI for now).
Anon #1
- Set far-off Expires
- Set ETag if possible
- Cache-Control: max-age=315360000
Anon #2 (have the reverse proxy cache the result if dynamically generated else Anon #1 rules apply)
- Cache-Control: public, s-maxage=3000
Anon #3
- Cache-Control: public, s-maxage=300
Logged In #1
- Set far-off Expires
- Set ETag if possible
- Cache-Control: max-age=315360000
Logged In #2 (have the reverse proxy cache the result if dynamically generated else Logged In #1 rules apply)
- Cache-Control: public, s-maxage=3000
Logged In #3
- Cache-Control: s-maxage=0, must-revalidate
What are your suggestions? I'll update the post as answers come in.