Modules are caching unrelated head elements

The support for Joomla 2.5 ended on December 31, 2014. Possible bugs in Joomla 2.5 will not be patched anymore. This forum has been closed. Please update your website to Joomla 3.x

Moderator: ooffick

Forum rules
Please use the official Bug Tracker to report a bug: https://issues.joomla.org
Locked
drewgg
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 161
Joined: Thu Oct 30, 2008 7:27 pm

Modules are caching unrelated head elements

Post by drewgg » Thu Dec 15, 2011 10:29 pm

Description:

If you cache modules then the cache of those modules will include all custom head elements (ie, elements added via addCustomTag()), even if they aren't associated with that module. This will then cause those custom head elements to be added to other pages inappropriately.

Here is what let me to this:

After clearing my site's cache and loading an article, then a second article, that second article has some of the head elements that belonged to the first article (when viewing the source). If I visit a third article then that article will have some of the head elements from both the first and the second article.

Turning off cache makes the issue go away. This happens from both Conservative caching and Progressive caching.

When I looked through the files in my /cache/ folder I discovered the extra head elements that were being added were all part of module cache files (files in "/cache/mod_custom/" for example). Turning off caching for all modules (via the modules' Advanced Options parameters) also makes the issue go away.

I then researched why modules were storing head elements that had nothing to do with that module (eg, a mod_custom module's cache was storing addCustomTag() elements from a content plug-in). I found in:

/libraries/joomla/application/module/helper.php -> moduleCache() :

line 420:

Code: Select all

		$wrkaroundoptions = array (
			'nopathway' 	=> 1,
			'nohead' 		=> 0,
			'nomodules' 	=> 1,
			'modulemode' 	=> 1,
			'mergehead' 	=> 1
		);
The 'nohead'=>0 and 'modulemode' => 1 option causes Joomla to cache the custom head elements with every module cache (nohead=0 would cause it to cache all head elements but modulemode=1 unsets stuff like the title, description, links, etc). You can see where this happens here:

/libraries/joomla/cache/cache.php -> setWorkarounds()

line 529:

Code: Select all

		if ($loptions['nohead'] != 1) {
			$cached['head'] = $document->getHeadData();

			if ($loptions['modulemode'] == 1) {
					unset($cached['head']['title']);
					unset($cached['head']['description']);
					unset($cached['head']['link']);
					unset($cached['head']['links']);
					unset($cached['head']['metaTags']);
			}
		}
Notice that $cached['head']['style'], $cached['head']['scripts'], $cached['head']['custom'] and a few others are not unset for modules. If it's not unset, it gets added to the module's cache file.

When that module's cache is read (when another page is loaded) the 'mergehead'=>1 causes the cached custom head elements from the module to be added to the page's head (de-dupping any identical elements). Therefore, changing 'nohead'=>0 to 'nohead'=>1 causes this issue to go away. This is isn't a solution though, because this would cause fatal issues for any module that's use custom head elements (I didn't test this statement it though).

Am I right in seeing this as a bug or am I missing something? For now I have turned off cache for all modules.


Reported on:
Joomla! 1.7.3 Stable [ Ember ] 14-Nov-2011 14:00 GMT
Platform 11.2.0 Stable+Modified [ Omar ] 27-Jul-2011 00:00 GMT

Affected functions:
Module Caching

Related files:
/libraries/joomla/application/module/helper.php
/libraries/joomla/cache/cache.php
/libraries/joomla/document/html/html.php

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: Modules are caching unrelated head elements

Post by infograf768 » Sun Dec 25, 2011 6:52 am

Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

drewgg
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 161
Joined: Thu Oct 30, 2008 7:27 pm

Re: Modules are caching unrelated head elements

Post by drewgg » Tue Dec 27, 2011 7:30 pm

infograf768 wrote:Please post your findings here:
http://joomlacode.org/gf/project/joomla ... m_id=27503
Done.

It was suggested that this was ultimately a Joomla Platform issue and should be brought up on that tracker system. The ticket can be found here: https://github.com/joomla/joomla-platform/issues/675


Locked

Return to “Joomla! 2.5 Bug Reporting”