xoops forums

Mithrandir

XOOPS is my life!
Posted on: 2004/1/28 21:51
Mithrandir
Mithrandir (Show more)
XOOPS is my life!
Posts: 6320
Since: 2003/6/21
#1

Module-wide caching - Important development

Draven has looked closely into this and found out why (at least some) modules don't work properly with the module-wide cache.

--=Important Bit=--

The header.php checks if there is a cached version of the requested page by seeing if the $xoopsOption['template_main'] is set, but since most modules include header.php as one of the first pages, the $xoopsOption['template_main'] will read system_dummy.html and not found as cached.

Therefore all the php code will be re-executed including SQL sentences and everything.

So to properly benefit from the module-wide cache, start every page of your module to first include mainfile.php, then determine which template to use (if it is necessary to evaluate and not just specify it) and set it with $xoopsOption['template_main'] = 'templatename';
BEFORE including root/header.php.

--=/Important Bit=--

Draven

Module Developer
Posted on: 2004/1/28 22:41
Draven
Draven (Show more)
Module Developer
Posts: 337
Since: 2003/5/28
#2

Re: Module-wide caching - Important development

Yep, that little bugger drove me nuts for a few hours trying to figure out why the cached pages "appeared" to work, but yet all the SQL calls in the module were still being made (as seen through the MySQL debug window). The culprit, as Myth mentioned above, was the improper placement of the header include.

brash

Friend of XOOPS
Posted on: 2004/1/28 23:03
brash
brash (Show more)
Friend of XOOPS
Posts: 2206
Since: 2003/4/10
#3

Re: Module-wide caching - Important development

Damn nice find there Draven . This could provide some pretty significant performance increases for people, especially for those with low end servers.

sunsnapper

Friend of XOOPS
Posted on: 2004/1/28 23:44
sunsnapper
sunsnapper (Show more)
Friend of XOOPS
Posts: 403
Since: 2002/4/10
#4

Re: Module-wide caching - Important development

Perhaps we could make this post sticky... and each module developer can post to this thread when they have updated their module with this fix.

brash

Friend of XOOPS
Posted on: 2004/1/29 0:08
brash
brash (Show more)
Friend of XOOPS
Posts: 2206
Since: 2003/4/10
#5

Re: Module-wide caching - Important development

Very good suggestion ^^

Mithrandir

XOOPS is my life!
Posted on: 2004/1/29 0:25
Mithrandir
Mithrandir (Show more)
XOOPS is my life!
Posts: 6320
Since: 2003/6/21
#6

Re: Module-wide caching - Important development

Team and Server Booking modules will be updated shortly with this.

The next News module will of course also include this solution.

dlh

Posted on: 2004/1/30 5:45
dlh
dlh (Show more)
Posts: 182
Since: 2002/2/20
#7

Re: Module-wide caching - Important development

Draven,

Thanks for the find. This is pretty huge.

Wierd how it was something so simple, huh? Makes you want to smack your forehead and do a Homer Simpson.

"DOH!"



Dan (dlh)

Herko

XOOPS is my life!
Posted on: 2004/1/30 10:18
Herko
Herko (Show more)
XOOPS is my life!
Posts: 4238
Since: 2002/2/4 1
#8

Re: Module-wide caching - Important development

Topic has been Stickyed

Herko

recupsoft

Friend of XOOPS
Posted on: 2004/1/31 21:36
recupsoft
recupsoft (Show more)
Friend of XOOPS
Posts: 151
Since: 2003/10/30
#9

Re: Module-wide caching - Important development

Such XOOPS improvements are really welcome

But... for bad programers as me,
Can you provide an example of code before/after

Mithrandir

XOOPS is my life!
Posted on: 2004/1/31 23:06
Mithrandir
Mithrandir (Show more)
XOOPS is my life!
Posts: 6320
Since: 2003/6/21
#10

Re: Module-wide caching - Important development

Before:
<?php
include ('../../mainfile.php');
include (
XOOPS_ROOT_PATH.'/header.php');

code[...]

$xoopsOption['template_main'] = "templatename";

code [...]

include (
XOOPS_ROOT_PATH.'/footer.php');
?>

after:
<?php
include ('../../mainfile.php');

code[...] //As little as possible, to determine template name

$xoopsOption['template_main'] = "templatename";
include (
XOOPS_ROOT_PATH.'/header.php');

code[...] //Main code area

include (XOOPS_ROOT_PATH.'/footer.php');
?>