Skip to content

Conversation

@fevangelou
Copy link
Contributor

@fevangelou fevangelou commented May 15, 2019

Pull Request for Issue #24917

Summary of Changes

(updated to provide more context and reflect comments below)
Many Joomla core modules (e.g. mod_menu, mod_custom etc.) as well as lots of third-party modules still use "cache" as the de-facto XML parameter to allow for a module to be cached along with the rest of Joomla's rendered content (when Joomla caching is set to "on") or to be excluded from Joomla's cache overall.

The current check in JModuleHelper::moduleCache() is currently invalid as it does not count for the XML parameter "cache" (present in most modules), but only for "owncache", which was introduced in Joomla 2.5.

By not including the check for "cache" in JModuleHelper::moduleCache(), a module that uses that XML parameter will always be cached regardless of its setting (when Joomla caching is enabled).

Testing Instructions

Switch Joomla cache on and set some (affected) Joomla module (e.g. mod_menu) to be excluded from cache.

Expected result

The module instance should not be cached.

Actual result

It's cached. That's because the XML file for that module utilizes the parameter name "cache" which is not checked before deciding whether a module should be cached or not.

Documentation Changes Required

I would recommend a pointer to this https://docs.joomla.org/J2.5:What%27s_new_in_Joomla_2.5 in the docs that refer to module development.

@fevangelou fevangelou changed the title B/C fix - Check for both "cache" & "owncache" XML parameter in module [J3.9.x] B/C fix - Modules (including core) using the "cache" XML parameter always cached, regardless of that parameter's value May 15, 2019
@mbabker
Copy link
Contributor

mbabker commented May 15, 2019

You're on the right path but this looks incomplete. #20626 for reference.

The intent was to turn it into strict checks and support proper filter definitions. So the "owncache" param is strictly checked for both integer 0 and string 0, it looks like the "cache" param needs both of those checks as well.

FWIW, that line hasn't checked the "cache" param since at least 1.7 so something was probably messed up even before that PR if this patch is needed.

@fevangelou
Copy link
Contributor Author

Actually, have a look at my intro here: #24917

Without "cache" in that if statement, all modules with that XML param (even core modules!) will always be cached, even if you set that param to "no".

@fevangelou
Copy link
Contributor Author

In other words, I would recommend we patch this now, until more time is found to properly address cache flag overriding. Which by the way needs some reworking as I can't dynamically set for example "cachemode". It always switches to the preset "oldstatic" as referenced here: https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Document/Renderer/Html/ModuleRenderer.php#L84

@mbabker
Copy link
Contributor

mbabker commented May 15, 2019

That's why the check essentially needs to be this:

// Both of these checks use strict checks purposefully to omit other falsy values, the form definition should use an integer filter
$ownCacheDisabled = $moduleparams->get('owncache') === 0 || $moduleparams->get('owncache') === '0';
$cacheDisabled = $moduleparams->get('cache') === 0 || $moduleparams->get('cache') === '0';

if ($ownCacheDisabled || $cacheDisabled || $conf->get('caching') == 0 || $user->get('id')) {
    $cache->setCaching(false);
}

It covers both the param that seems to have been missing forever and a day (this is the line's blame at 3.7.5 and shows it had no changes in years) while also moving forward with the bit about encouraging forms to be properly filtered and using correct data types.

@fevangelou
Copy link
Contributor Author

Sorry, I missed the quotes.

You're right, it should be the 2 checks for owncache, plus 2 more for cache.

@fevangelou
Copy link
Contributor Author

PR updated.

@fevangelou
Copy link
Contributor Author

fevangelou commented May 15, 2019

Thank you.

As a sidenote, (as I briefly mentioned above) I've found that "cachemode" cannot be dynamically set from within a module's code, but only through its XML parameters. So switching for example from the "oldstatic" caching mode to the newer (default) "static" or any of the other options that were introduced in Joomla 2.5 is not possible through a simple module update. The developer must add the hidden cachemode XML parameter and then a site admin must open ALL modules and simply resave them to get the new value in and allow for more efficient caching overall.

File: https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Document/Renderer/Html/ModuleRenderer.php#L83:

// Default for compatibility purposes. Set cachemode parameter or use JModuleHelper::moduleCache from within the module instead

In other words, adding just this in a module's code:

<?php

// module prep stuff here

$cacheparams = new stdClass;
$cacheparams->cachemode = 'safeuri';
$cacheparams->class = 'someHelper';
$cacheparams->method = 'someMethod';
$cacheparams->methodparams = $params;
$cacheparams->modeparams = array('whatever' => 'int');

$list = JModuleHelper::moduleCache($module, $params, $cacheparams);

// continue to render module output here

...would completely ignore the new cachemode set, maintaining "oldstatic" as this module's cachemode.

Do I understand correctly that the original intent was to be able to set cachemode dynamically?

@mbabker
Copy link
Contributor

mbabker commented May 16, 2019

Do I understand correctly that the original intent was to be able to set cachemode dynamically?

Sounds like that was the case but it completely missed the mark.

@ghost ghost changed the title [J3.9.x] B/C fix - Modules (including core) using the "cache" XML parameter always cached, regardless of that parameter's value B/C fix - Modules (including core) using the "cache" XML parameter always cached, regardless of that parameter's value May 16, 2019
@ghost
Copy link

ghost commented Jul 8, 2019

@joomlabeat please test (how to: https://docs.joomla.org/Testing_Joomla!_patches)

@joomlabeat
Copy link
Contributor

I have tested this item ✅ successfully on b82c9ca

Excluding modules from cache works the same for both caching levels.
*Not sure if this is desired though - as I have read documentation and articles around the web that says only conservative cache would allow modules to be excluded from cache by using their cache field.

As a sidenote to @fevangelou sidenote:
After saving a module with a specific cachemode for the first time, it looks like is impossible to update this setting by simply changing the cachemode default value in the xml. After the first saving, the cachemode field will always get the initial stored value from the database, the form will be populated with this value and will be re-submitted each time, disregarding what default value the xml might have.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24916.

@brianteeman
Copy link
Contributor

After saving a module with a specific cachemode for the first time, it looks like is impossible to update this setting by simply changing the cachemode default value in the xml. After the first saving, the cachemode field will always get the initial stored value from the database, the form will be populated with this value and will be re-submitted each time, disregarding what default value the xml might have.

Yes and that is the intended behaviour

@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on b82c9ca


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24916.

@Quy
Copy link
Contributor

Quy commented Jul 22, 2019

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24916.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 22, 2019
@HLeithner HLeithner merged commit 7e1276c into joomla:staging Jul 22, 2019
@HLeithner
Copy link
Member

thx

1 similar comment
@HLeithner
Copy link
Member

thx

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 22, 2019
@HLeithner HLeithner added this to the Joomla! 3.9.11 milestone Jul 22, 2019
@ghost
Copy link

ghost commented Jul 23, 2019

@viocassel can you please mail me: [email protected]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants