You are here: Re: how to cache pages with login names « PHP Programming Language « IT news, forums, messages
Re: how to cache pages with login names

Posted by Colin McKinnon on 02/19/07 20:43

lister wrote:

>
> I guess I could cache the username in the user's session data to save
> a DB lookup (or maybe even a cookie to save looking up any session
> data at all). However, I still cannot see how I can ever cache the
> resultant page since the header is user specific, even if everything
> else is static?
>
> How do other people handle this? Having the username at the top seems
> a pretty common design, so I guess the problem must have been tackled
> somehow?

HTTP specifically allows for this with the vary header (you'll need to send
an expires and/or a cache-control: max-age header too).

e.g.

header("Cache-control: max-age=86400; must-revalidate");
header("Vary: Cookie");

You can also cache parts of your code serverside (you should add code to
expire the cache):

$cache_key=$tmp_dir . md5($_SERVER['REQUEST_URI'] .
$_COOKIE[session_name()]);
if (file_exists($cache_key)) {
print file_get_contents($cache_key);
} else {
ob_start();
....
file_put_contents($cache_key, ob_get_contents());
ob_end_flush();
}

C.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация