0

I'm writing a web app, and I'm having a serious problem with too much caching. I use CakePHP 2.0 if that matters at all.

Anyways basically the problem I'm having is the browser caches my app way too often. For example if I have a user fill out a form and then add a flash message and redirect the user to their dashboard the flash message appears just fine, but it appears until I refresh the page. So if I navigate away from that page and navigate back, the flash message is still there. That's just a small irritant, the bigger issues are when pages actually change depending on user action.

For example on the admin side I may update a users status which changes their dashboard in some way. The problem is the updated dashboard will not be seen without a refresh. What a hassle!

My question isn't how to fix this, I know how to stop caching all together. It seems like caching is an important part of a web apps performance though and I don't want to stop caching all together as I can see it slowing things down.

So what is normally done in these situations? Should I just stop the page from caching all together? Seems like an extreme solution. Or should I just link to all of my pages with something like:

http://mywebsite.com/user?t=<?php echo time(); ?>

Or is there something else that I'm missing? Any advice is appreciated!

1 Answer 1

2

Would the answers outlined here - How do I completely disable caching in Cakephp? - work?

Fixing the flash message problem is hard - because the flash message is part of the output HTML, there is no way you can get rid of it on a back button event.

For the dashboard, I recommend turning off browser caching ... but that's not going to solve any inbuilt caching that CakePHP has.

Sounds like what you need is some way of invalidating the cache ONLY where there is an update - you could add a method to your add()/edit() methods to completely delete the cache upon a successful save() event - that seems the only foolproof method that would work for your case.

2
  • Well what I did was add: $this->response->disableCache(); to my AppController's beforeRender() callback. That calls the headers to tell the browser not to cache. Apparently it still caches images just not HTML/CSS/JS? Anyways my solution for now seems to be to stop browser caching all together and then add some CakePHP specific caching. That way I have more control of what is and isn't cached. I don't know if this is a good idea or not, but the browser caching is really screwing everything up. Mar 31, 2012 at 15:11
  • Images might definitely be cached - that's a server/Apache setting, rather than a CakePHP setting. If you have control over your server/Apache, you might want to look at the caching/expires settings for Apache to disable image and other static asset caching.
    – Suman
    Apr 2, 2012 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.