开发者

Are there any problems with this browser-cache system?

开发者 https://www.devze.com 2023-01-06 00:36 出处:网络
I have a app-type web site with a couple of long list pages (such as a list of companies grouped by country) that take a few seconds to build, but don\'t change very often.I use APC & Memcache to

I have a app-type web site with a couple of long list pages (such as a list of companies grouped by country) that take a few seconds to build, but don't change very often. I use APC & Memcache to some extent, but I also thought "why have it hit the server at all" so I devised this:

ob_start();
requ开发者_如何学运维ire_once '../bootstrap.inc.php'; request_router(); // MVC style system, all work starts here

header("Expires: " . gmdate("D, d M Y H:i:s",time()+300) . " GMT"); // 5 minutes
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: private");
header("Pragma: private");
echo ob_get_clean();

I just basically want to have it set so that when they go to the big list, it's built, but when they click into a link, then click another link to return to the list, it doesn't check to rebuild the list every time.

Spot any flaws before I try to implement it?

(FYI, I tried to do this with ExpiresActive in apache, but I couldn't get it to work; this seems easier to me, though, and in a place that makes it easier for me to control the Expires header)


Can't see any problems with that.

If you wanted more flexibility then you could make the value you add to get to the expiration time a variable that could be set elsewhere in your MVC code but defaulting to 300 if not set. That way you can set different expiration time for different pages and even set it to a negative value for pages you never want caching.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号