Page 1 of 1
[SOLVED] No module caching?
Posted: Sun Jul 28, 2013 6:48 pm
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?
Re: No module caching?
Posted: Mon Jul 29, 2013 12:54 am
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.
Re: No module caching?
Posted: Mon Jul 29, 2013 12:50 pm
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.
Re: No module caching?
Posted: Mon Jul 29, 2013 5:21 pm
by calguy1000
no smarty caching will work while you're logged in as an administrator.
logout or use a different browser to test.
Re: No module caching?
Posted: Mon Jul 29, 2013 7:45 pm
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.
Re: No module caching?
Posted: Mon Sep 30, 2013 4:21 pm
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?
Re: No module caching?
Posted: Mon Sep 30, 2013 4:43 pm
by calguy1000
Modules called from within {content} blocks will also not cache.
You would have to call them directly from the template.
Re: No module caching?
Posted: Mon Oct 07, 2013 11:09 pm
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?
Re: No module caching?
Posted: Mon Oct 07, 2013 11:16 pm
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);
Re: No module caching?
Posted: Tue Oct 08, 2013 1:11 am
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.