0

hello,

I am trying to experiment with page caching. I would like my page to be cached by the browser for 15 mins. Because the page content does not change much but it downloads thousands of the same records from the database every time the page loads.

I am generating the following header:

<meta http-equiv="Expires"  content="Mon, 21 Sep 09 14:26:47 +0000" />
<meta http-equiv="Cache-control" content="private" />

with the following php code:

gmdate(DATE_RFC822, (mktime() + 900));

I am also printing out the the current time on the page to check if the page is really being cached or not.

echo date("H:i:s");

It is my understanding that the time would not update on the web page if the page is really being cached.
Unfortunately it's not.

Kindly help. Any advice would be appreciated.

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by digital-ether
0

hello,

I am trying to experiment with page caching. I would like my page to be cached by the browser for 15 mins. Because the page content does not change much but it downloads thousands of the same records from the database every time the page loads.

I am generating the following header:

<meta http-equiv="Expires"  content="Mon, 21 Sep 09 14:26:47 +0000" />
<meta http-equiv="Cache-control" content="private" />

with the following php code:

gmdate(DATE_RFC822, (mktime() + 900));

I am also printing out the the current time on the page to check if the page is really being cached or not.

echo date("H:i:s");

It is my understanding that the time would not update on the web page if the page is really being cached.
Unfortunately it's not.

Kindly help. Any advice would be appreciated.

Try sending them as HTTP headers instead of HTML tags.

Example:

header('Cache-control: private');
header('Expires: '. gmdate(DATE_RFC822, (mktime() + 900)) );
0

hello,
Doing that generated generated a header error. It said that header already sent. I think I am not allowed to a use a php header and a html header.

0

Thank you. It is now working when I press the back button.
But it does not work when I click on a link in the navigation.
Would you know why that is?
Many thanks in advance.

0

Thank you. It is now working when I press the back button.
But it does not work when I click on a link in the navigation.
Would you know why that is?
Many thanks in advance.

What browser are you using.

I get a the timezone difference at the end of the date when using DATE_RFC822. Maybe the browser does not like that.

eg:

Wed, 23 Sep 09 04:47:19 +0000

Maybe using this would work:

gmdate('D, d M Y H:i:s').' GMT'

This would be equivalent to the example at:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21

And documented at:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1

Even though RFC 822 does define that the time difference can be used at the end of the date, you never know if a browser will accept it.
http://www.ietf.org/rfc/rfc0822.txt

See if that does it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.