[eluser]Xeoncross[/eluser]
Caching the HTML output of non-important pages (like blog posts) really helps to speed up a site by skipping the loading of the entire system (and rendering time) and just spiting out a pre-made copy of the page. This would be one way you can keep large waves of users to your site index or whatever from eating resources.
However, one of the problems of caching pages is that in order to check wither or not you can show the page - you have to load the system (DB, Session lib, etc) to check if the user is logged in. This kind of defeats the point of the showing the cached page since you just wasted all that memory anyway.
With the session lib loaded you can then determine if it is safe to show a cached version of the page or if you should re-render the page for the logged in user. And vis-versa; a page rendered for a logged-in user shouldn't be shown to a guest!
So here is my idea. Since most sites use cookies for sessions & cookies can be checked without the loading of any libraries -
why not check them?
At first I thought that I would test for the existence of ANY cookie
Code:
if(empty($_COOKIE)) {
show_cache();
die();
}
...
But the problem is that in order for the page to be created the first time - the whole system would have to be loaded and then at the end of all that a session would have already been started for the user so I couldn't create the cache because the check would now fail.
Code:
...
if(empty($_COOKIE)) {
create_cache();
die();
}
So then I thought of another way to handle this - Perhaps you could set a cookie called "logged_in" in addition to the session cookie when a use successfully logs in. Then you could test for "logged_in" cookie and the absence would prove this is a guest wither they have a session or not. It would even work for non-cookie user agents (false/non-existent cookie as a sign for a guest).
Any Ideas?
Quote:NOTE: this is only pertaining to full page caching. partial page caching (widgets, SQL, etc) should be handled with memcached and or other methods.