[SOLVED] No module caching?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

[SOLVED] No module caching?

Post by krussell »

I'm working on a custom module, and couldn't get caching to work. I stuck some debug code in the News module, and that doesn't seem to be caching earlier.
I have enabled all the caching options in Admin, so what else am I missing in the CMSMS setup that could be stopping module caching?
Last edited by krussell on Tue Oct 08, 2013 1:12 am, edited 1 time in total.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

Just to clarify, I set "Enable Smarty Caching" to "Yes" and "Cache Module Calls" to "Module Decides" in the Admin settings.

After reviewing the Smarty documentation here:

http://www.smarty.net/docs/en/api.is.cached.tpl

I added the following line to News module action.default.php as a test:

$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);

After doing this, the News module caching started working correctly. I tried the same test on my custom module, and again, the caching worked correctly.

So the Admin cache settings don't seem to be having any effect for me, but manually forcing caching with the code mod above did work.
I am using CMSMS 1.11.4, running on a local Uniform Server installation with PHP 5.4.11.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

Forgot to add - apologies if this is in the wrong forum. I added it here because the issue was originally triggered by developing a custom module, but could I ask an Admin to please move the topic if it is more appopriate to have it in another area? Thanks.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: No module caching?

Post by calguy1000 »

no smarty caching will work while you're logged in as an administrator.
logout or use a different browser to test.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

Thanks - I was not aware of that feature.

I have just tried using a different browser, and have also tried logging out and using the original browser, but I still get the same result. The news module is not retrieving cached content unless I explicitly set caching by inserting the line
$smarty->setCaching(Smarty::CACHING_LIFETIME_CURRENT);
in the default action.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

Apologies for resurrecting an old thread, but I have just returned to developing my module after a break.

I have been using News as an example on which to base the module I am developing, but I am still unable to see smarty caching working in the News module. I have tried inserting debug code on a production version of my site, as well as on a local installation, and get the same results, even when all the caching options are set, the News page is set as cacheable, and I log out of admin. No cached page file is created in the cache directory.
If I modify the News module and explictly set the session lifetime, as documented above, I can see the caching working correctly.

I'm a bit stumped about where else I can debug the caching process to understand what is wrong with my setup. Are there any server level settings that could be causing a problem here?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: No module caching?

Post by calguy1000 »

Modules called from within {content} blocks will also not cache.

You would have to call them directly from the template.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

Thanks again. I am using the module inside the {content} block which would explain why I am not seeing caching.

My module calls a 3rd party service for data, and does some template processing to format this, but I don't need it to update on every view, so I was interested in caching to maximise performance.

I have read the documentation on caching again, and if i understand this correctly, it looks like the best options are to enable the "allow browser caching" option, or try and engineer my template so I can call the module directly, rather than placing it within content?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: No module caching?

Post by calguy1000 »

My module calls a 3rd party service for data, and does some template processing to format this, but I don't need it to update on every view, so I was interested in caching to maximise performance.
I would do my own caching. Some of my modules do this type of thing quite regularly:

Code: Select all

$cache_file = TMP_CACHE_LOCATION.'/someuniquestring';
if( !file_exists($cache_file) || filemtime($cache_file) + 3600 < time() ) {
   $data = file_get_contents($some_url);
   file_put_contents($cache_file,$data);
}
return file_get_contents($cache_file);
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
krussell
Forum Members
Forum Members
Posts: 32
Joined: Wed May 16, 2007 2:00 pm

Re: No module caching?

Post by krussell »

That's really useful, and I have adopted your suggestion to cache my rendered template content as a file. This does exactly what I want.

Many thanks for the advice on this; I have a much better understanding of the caching options and approach now.
Post Reply

Return to “Developers Discussion”