Prevent caching for particular action

I have an action that I want providing realtime data at all times (it’s returning json to an ajax request), and it’s currently caching the data by default. How can I override this behavior?

Yii does not cache the output of any action by default. It’s probably the browser that is caching your response. How do you create your request? The usual way to prevent browser caching is to attach an arbitrary timestamp parameter (unique per request) to the request URL, which will be ignored on the server side:


Huh… well I cleared the browser’s cache and I remember it still happening. I’ll definitely try your method. Thanks!

If you use jQuery.ajax or some of it’s shorthand methods like jQuery.get, check out the cache option. It will handle this automatically for you.

That’s exactly what I’m doing, but I just used your timestamp method. I’m only using ajax to get, so the get url will refresh each time I post the form. Thanks again!


So, it works now?