Keyword

Invalid expires header

  • Pavel Poles
  • Pavel Poles's Avatar Topic Author
  • Offline
  • New Member
More
2 years 8 months ago - 2 years 8 months ago #179346 by Pavel Poles
Invalid expires header was created by Pavel Poles
Hi, 
I found caching issue in K2 item view (K2 2.10.3, Joomla 3.9.28).
In com_k2/views/item/view.html.php is called function 

JResponse::allowCache(true);

This causes that Expires header is set to response by Joomla 15 minutes in future, regardless caching is enabled or not. What it cause is if user is logged in, opens some K2 article, then log out, and display the article again, the whole page is still displayed as he is logged in (browser takes it from disk cache, not from server). An opposite, user is not loggedn in, displays an article (which is for example just for logged in users), login then, go back to article, and page is still disaplyed as he is not logged in.

Moreover, when cache is enabled in Joomla global configuration System K2 plugin adds expiration header just for guests. This solves issue Logged in -> logout, but opposite still remains. So when user is not loggedn in, then login, he still sees wrong page, as he is not logged in. 

There is 'x-logged-in' header, however this seems to work only when Varnish cache is installed on server.

I didn't find way, how to disable this behavior, without hacking K2. Is this known issue, or am I doing something wrong?

thanks

Pavel
Last edit: 2 years 8 months ago by Pavel Poles. Reason: Invalid code rendering

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179427 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
Hi,

Same issue here.

K2 v2.10.3  is overriding the default Joomla headers with its Custom HTTP headers and there is no way to disable them.

JResponse::setHeader('Cache-Control', 'public, max-age='.$cacheTTL.', stale-while-revalidate='.($cacheTTL*2).', stale-if-error='.($cacheTTL*5), true);
JResponse::setHeader('Expires', gmdate('D, d M Y H:i:s', time()+$cacheTTL).' GMT', true);

We have articles that show a summary for guests or the full content for members. It doesn't work anymore with these headers. Once the article is cached with a long expiration, it is not requested again by the browser when the user logs in.

Best Regards




 

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179428 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
Going back to K2 v2.9, these were the only custom headers:

        // Custom HTTP headers
        $user = JFactory::getUser();
        if (!$user->guest) {
            JResponse::setHeader('X-Logged-In', 'True', true);
        } else {
            JResponse::setHeader('X-Logged-In', 'False', true);
        }
        JResponse::setHeader('X-Content-Powered-By', 'K2 v'.K2_CURRENT_VERSION.' (by JoomlaWorks)', true);

 

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179429 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
The new headers were introduced between K2_v2.10.2 and K2_v2.10.3.

Best Regards

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179431 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
Two more places where K 2.10.3 forces the expiration header:

plugins/system/k2/k2.php, line 717
JResponse::allowCache(true);

components/com_k2/views/item/view.html.php
JResponse::allowCache(true);

If these lines are enabled, Joomla sends a header with expiration +15'

// Expires.
$this->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 900) . ' GMT');

 

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179459 by JoomlaWorks
Replied by JoomlaWorks on topic Invalid expires header
If caching is enabled, K2 will indeed emit these headers.

However this will be optional in the last release of the 2.x series (K2 v2.11) by the end of September. It will be optional as it confused some users indeed.

Until then, the easiest way to disable it is by commenting out these 2 lines in the item view: github.com/getk2/k2/blob/master/components/com_k2/views/item/view.html.php#L475-L478

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179465 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
Hi, great news!

It would be great if we could have the same headers as before.

It is not clear to me the benefits of emitting custom headers (Cache-Control, Expires, and Pragma) in the K2 System Plugin (onAfterInitialise).

BTW: Thank you for your recipe for Varnish ! It helped a lot to handle traffic on a massive site.

Best Regards,
Anibal Sanchez - Extly.com

 

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #179480 by JoomlaWorks
Replied by JoomlaWorks on topic Invalid expires header
If Joomla's caching is on, headers are not properly passed on subsequent requests (only on the first page load before everything is cached). This is obviously a Joomla bug. That is why I use a script tag output (which is not rendered at all by the browser since the "type" is custom) so the K2 "system" plugin can read it and essentially re-emit the correct headers.

These headers can be used by other apps or caching proxies then for a better caching strategy.

It's really all about properly caching content, especially on sites with extremely large traffic (which we've been working on almost exclusively the past 13 years or so).

In most of our setups, we use K2 with URL Normalizer to prepare the right HTTP headers and then Memcached (for Joomla's cache storage), Nginx as web server and Varnish as caching proxy. This allows to fully control caching (end to end) entirely through Joomla.

...And I'm glad my Varnish setup helped you as well :)

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 2 years 7 months ago by JoomlaWorks.

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #180735 by Anibal Sanchez
Replied by Anibal Sanchez on topic Invalid expires header
I've updated to the latest version 2.11, and the issue is still active.

I've opened the issue on GH to follow the case there: github.com/getk2/k2/issues/556

Best Regards

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum