32bitfloat
32bitfloat

Reputation: 771

how to cache 2 different contents of the same page

I wonder what is the best way to cache php-output where there is different content for logged-in users and for those who are guests. "Different" means that guests see less text and no comments and have less functionality on that page (e.g. they cannot mark the current page as favorite).

I could create one file for each "mode" in which a page can be visited. So I would have to check whether a user is logged in or not and then decide which cachefile I serve.
On the other hand I could create only one file for each page and use php-code inside this file to decide which content (or better, how much of it) is printed out.

I would prefer the second option because it would mean that the content or part of the content isn't stored twice. Furthermore I could be sure that no user could access the complete content by just calling the cachefile (it uses hash in the name anyway). However I'm not that sure if I included all relevant facts in my consideration. I'd like to know if I missed some (dis-)advantages or other possible methods.

Upvotes: 0

Views: 52

Answers (1)

Valerij
Valerij

Reputation: 27748

i would prefer the first way, it also gives you the ability to cache those views differently eg. when a new comment is added only the member cache need to be rerendered; also the second forces you to generate code, and include later, sounds like php-selfmodifying-code, hell to debug

Upvotes: 1

Related Questions