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->call
$cache->setCaching joomla
displaying remote RSS feeds joomla 1.5
joomla jfactory cache clean
joomla 1.5 cachowanie
using cache function joomla 1.5
?cachecleaner= joomla query
joomla cache->call
how to refresh cache in joomla
joomla rss refresh
joomla and cache 2009
clean cache rss joomla
joomla code cache
JFactory::getConfig() expensive?
Newsletter without refresh page for joomla 1.5
joomla cache function results
dont clear cache joomla
joomla JFactory::getCache
joomla 1.5 clean cache
using cache in joomla
abilita cache in joomla feed
joomla cache->setCaching








