I recently had a problem on our website with caching in our CakePHP framework. We initially had caching turned on. And then we started noticing when we submitted a form, our changes wound not be updated until we manually refreshed the page.
So let’s say I have a row of users. I choose to delete one of the users. I click on delete, hit submit and cake removes that user from my table. Cake then redirects me back to same page, but the deleted user is still listed on our page. Once we manually hit the refresh button on our browser, then our deleted user disappears from our form page.
We scratched our heads and tried figuring out why this was happening. We turned off all caching and even added the <cake:nocache> tag. No matter what we did, we could not get rid of the problem.
After much research, we realized that the browser itself was actually caching the previous form page. So we added this snippet of code to our app controller.
$this->disableCache();
This is used to tell the user’s browser not to cache the results of the current request. The headers sent to this effect are:
Expires: Mon, 26 Jul 1997 05:00:00 GMT Last-Modified: [current datetime] GMT Cache-Control: no-store, no-cache, must-revalidate Cache-Control: post-check=0, pre-check=0 Pragma: no-cache
I hope this saves you some time. If you find a better way fixing this problem, please leave a comment.