From a custom plugin controller, I am returning data as json using $this->returnJson($data). I need to be able to set the Cache-Control headers for my forward cache proxy to handle caching correctly.

I tried using HeaderHelper::setExpires(300), but JsonHelper::sendJsonHeaders(), which is called by $this->returnJson() from the controller, overrides setExpires by calling HeaderHelper::setNoCache().

Does anyone have any ideas for working around this or configuring returnJson? I can do the following in my controller (or create a helper of my own):

echo JsonHelper::encode($return);

but I'd rather use the super convenient returnJson function.

1 Answer 1


If you're running Craft CMS 2.6.2783, you can pass in an 'expires' key to the optional $options 2nd parameter of returnJson with the value set to the time in seconds that will be passed to the cache control expiration headers. If you ignore it, it will have the current behavior of not caching at all.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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