J3 Issue ?
avatar frankmayer
frankmayer
20 Dec 2017

Steps to reproduce the issue

Try to cache a JSON Document

Expected result

Cache and Expire Headers are set correctly.

Actual result

Expire header is set to the past.
Cache headers are set to not cache

System information (as much as possible)

Latest Joomla 3.8.3

Additional comments

I stumbled upon this while developing a module. I was using com_ajax for communication, when I couldn't get the headers right, trying to take advantage of client-side caching.

I set the $app->allowCache(true), which should do the job, one would think, but this wasn't working.
I found out that the render() function in JsonDocument has a hardcoded:

$app->allowCache(false);

at https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Document/JsonDocument.php#L71

If I remove that line, it works fine, though I don't know if any extensions would have problems, if browser cache on the site would be enabled.

This line should not be there at all, or handled differently in order to not break b/c.
it is also an issue, as the given parameter is not honored.

I believe this should be fixed, as caching JSON responses on the client is legit and Joomla should not get in the way of that.

For now, in my module I did an ugly workaround by just returning the headers and data and exiting prematurely. However, I would prefer to not skip the remaining Joomla stuff that would be happening, like some event triggers being handled by some plugins.

I am happy to provide a PR for this.

avatar frankmayer frankmayer - open - 20 Dec 2017
avatar joomla-cms-bot joomla-cms-bot - change - 20 Dec 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 20 Dec 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Dec 2017
Category Libraries
avatar brianteeman brianteeman - change - 25 Mar 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar brianteeman brianteeman - change - 25 Mar 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-03-25 18:03:21
Closed_By brianteeman
avatar brianteeman
brianteeman - comment - 25 Mar 2018

Closing this here as there is another discussion on #19941

avatar brianteeman brianteeman - close - 25 Mar 2018

Add a Comment

Login with GitHub to post a comment