Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear cache in Controller CakePHP 2.x?

I am working a properties website where user creates the listing and later to save it, we ask him to connect via Facebook. Currently it is working nice but, when I create another property (say a User did not login) and later I just go back to that page of creating property and later connect via facebook then.. it does log the user in but, does not create the property.. I tried various things and later I figured out that once I clear browser cache, it is creating the properties.

So, my question is, how to clear cache in browser using CakePHP 2.x?

Also, I have tried:

Pure HTML :

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

however, it did not help. Is there a way to do it via CakePHP itself? or is it Facebook thing which needs to be addressed?

Please advise.

PS: clearCache() does not work I don't know why.

like image 488
Karma Avatar asked Jul 18 '26 22:07

Karma


2 Answers

You cannot clear a browser's cache unless you are actually the one using the browser. (eg. File->Options->Clear Cache)

What you're talking about is just telling the browser to not cache YOUR page in the first place - which it appears you already know how to do.

But once it's cached, it's cached by THEIR browser, not YOUR code. It would be a security issue and easily abusable among other things to allow you to delete the users cache.

like image 89
Dave Avatar answered Jul 20 '26 18:07

Dave


You can use CakeResponse::disableCache()

Example:

 <?php
        public function search() {
        // do something.
            $this->response->disableCache();
       }
like image 21
Younus Ali Avatar answered Jul 20 '26 16:07

Younus Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!