My mistakes

Cakephp how to avoid browser page caching

Posted on: February 21, 2008

Upto cakephp 1.1.19.x there is no builtin function for this so,One solution is

Send the below headers before render a view

header(“pragma: no-cache”);
header(“Cache-Control: no-cache, must-revalidate”);
header(“Expires: Mon, 26 Jul 1997 05:00:00 GMT”); // Date in the past

you can place the above code in the function beforeRender or layout file.

Cakephp 1.2.x contains a function Controller::disableCache() this will avoid the browser page caching by sending the corresponding headers.

Advertisements

2 Responses to "Cakephp how to avoid browser page caching"

Exactly
You can apply this to entair pages by defining the beforeRender function inside app_controller

/**
* beforeRender() Called after the controller action is run, but before the view is rendered
*/
function beforeRender() {

header(“Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0”); // // HTTP/1.1
header(“Pragma: no-cache”);
header(“Expires: Mon, 17 Dec 2007 00:00:00 GMT”); // Date in the past

}

Or you can specify these headers in default.thtml layout between header tags

[…] Cakephp how to avoid browser page caching « vibeesh’s Weblog In CakePHP 1.2: Controller::disableCache() (tags: cakephp cache) Posted by Richard@Home Filed in 15 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: