Using Joomla 1.5 to cache expensive computations |
| Monday, 01 June 2009 | ||||
|
Joomla's cache system allows you to automatically cache the output and result of a function(in this example the '_fetch' static method from the 'Currency' class). Cache's purpose is to offload your servers (and remote servers if fetching remote data), and speed up page display. The $res will return the cached function result(if fresh enough). If the result is older than 'lifetime' seconds, the cache call will execute the function again, and store the result for another 'lifetime' seconds. In other words, the cache refreshes every 'lifetime' seconds. Take note that the class is not instantiated, we're just using it for namespace purposes. The actual call will be the same as calling Currency::_fetch() from PHP. The code below creates and uses a 'Currency' subfolder in Jomla's cache folder(if the cache system was configured for file storage in Joomla administration). To clear the cache, you may use Tools->Clean cache from Joomla administration. // cache subfolder(group) 'Currency', cache method: callback $cache= & JFactory::getCache('Currency','callback'); // save configured lifetime @$lifetime=$cache->lifetime; $cache->setLifeTime(86400/2); // check twice per day // save cache conf $conf =& JFactory::getConfig(); // check if cache is enabled in configuration $cacheactive = $conf->getValue('config.caching'); $cache->setCaching(1); //enable caching // Currency=classname, _fetch=static method. The $res will hold the cached return value // if the cache expired, the method will be called again and the result will be stored for 'lifetime' seconds $res = $cache->call(array('Currency','_fetch')); // revert configuration $cache->setCaching($cacheactive); Are you a Joomla/PHP/Web developer? You may want to check our list of freelance jobs websites.
Write Comment |
||||
| Last Updated ( Thursday, 18 June 2009 ) | ||||
Joomla stuff
Newsletter
Auto tags
joomla cache
joomla caching
Joomla 1.5 Cache
joomla clean cache
joomla 1.5 caching
using joomla cache
Joomla cache lifetime
joomla clear cache
JFactory::getCache
Joomla getCache
joomla auto clean cache
joomla rss cache
newsletter joomla 1.5
joomla $cache->call
newsletter for joomla 1.5
$cache->call Joomla
joomla refresh cache
joomla cache how to
joomla cache folder
how to use joomla cache
joomla caching system
Subscribe to newsletter joomla 1.5








