0
votes

I need to cache my home page, this far no prob, using reverse proxy is good enough

But I also need to include the header part with standalone (ESI) , so that I can check if user is connected and show his info "hello Vincent".

The problem is that if I do so, the home page (as every page) will have to test the session, and as I use PDO storage, I can see 2 query running on MySQL for every user/page.

So I tried to add a simple "is_connected" cookie, and check for its absence to render the logged-out version without asking session, but it seems that as long as I have a firewall letting anonymous user it will ask for session.

I'm running out of idea, I'd like to see what people do for this, the goal is no query at all on home page.

thanks

1

1 Answers

0
votes

The home page does not need to test the session. It should be publicly cached and contain the esi include tag:

<esi:include src="/home/header_fragment.html" />

Only the header_fragment resource needs to test the user's session for login. You can store a small cache of the logged in user's information (name, email, whatever) in a signed cookie and read that in header_fragment to determine logged in vs. logged out, and if logged in display the user's name instead of looking up the information in the data store.