Example #1
0
 /**
  * Module cache helper
  *
  * Caching modes:
  * To be set in XML:
  * 'static'      One cache file for all pages with the same module parameters
  * 'oldstatic'   1.5 definition of module caching, one cache file for all pages
  * with the same module id and user aid,
  * 'itemid'      Changes on itemid change, to be called from inside the module:
  * 'safeuri'     Id created from $cacheparams->modeparams array,
  * 'id'          Module sets own cache id's
  *
  * @param   object  $module        Module object
  * @param   object  $moduleparams  Module parameters
  * @param   object  $cacheparams   Module cache parameters - id or url parameters, depending on the module cache mode
  * @return  string
  */
 public function cache($module, $moduleparams, $cacheparams)
 {
     // [!] Deprecated. Needs to be refactored.
     return true;
     if (!isset($cacheparams->modeparams)) {
         $cacheparams->modeparams = null;
     }
     if (!isset($cacheparams->cachegroup)) {
         $cacheparams->cachegroup = $module->module;
     }
     $cache = \JFactory::getCache($cacheparams->cachegroup, 'callback');
     // Turn cache off for internal callers if parameters are set to off and for all logged in users
     if ($moduleparams->get('owncache', null) === '0' || $this->app['config']->get('caching') == 0 || \User::get('id')) {
         $cache->setCaching(false);
     }
     // module cache is set in seconds, global cache in minutes, setLifeTime works in minutes
     $cache->setLifeTime($moduleparams->get('cache_time', $this->app['config']->get('cachetime') * 60) / 60);
     $wrkaroundoptions = array('nopathway' => 1, 'nohead' => 0, 'nomodules' => 1, 'modulemode' => 1, 'mergehead' => 1);
     $wrkarounds = true;
     $view_levels = md5(serialize(\User::getAuthorisedViewLevels()));
     switch ($cacheparams->cachemode) {
         case 'id':
             $ret = $cache->get(array($cacheparams->class, $cacheparams->method), $cacheparams->methodparams, $cacheparams->modeparams, $wrkarounds, $wrkaroundoptions);
             break;
         case 'safeuri':
             $secureid = null;
             if (is_array($cacheparams->modeparams)) {
                 $uri = \Request::get();
                 $safeuri = new \stdClass();
                 foreach ($cacheparams->modeparams as $key => $value) {
                     // Use int filter for id/catid to clean out spamy slugs
                     if (isset($uri[$key])) {
                         $safeuri->{$key} = \Request::_cleanVar($uri[$key], 0, $value);
                     }
                 }
             }
             $secureid = md5(serialize(array($safeuri, $cacheparams->method, $moduleparams)));
             $ret = $cache->get(array($cacheparams->class, $cacheparams->method), $cacheparams->methodparams, $module->id . $view_levels . $secureid, $wrkarounds, $wrkaroundoptions);
             break;
         case 'static':
             $ret = $cache->get(array($cacheparams->class, $cacheparams->method), $cacheparams->methodparams, $module->module . md5(serialize($cacheparams->methodparams)), $wrkarounds, $wrkaroundoptions);
             break;
         case 'oldstatic':
             // provided for backward compatibility, not really usefull
             $ret = $cache->get(array($cacheparams->class, $cacheparams->method), $cacheparams->methodparams, $module->id . $view_levels, $wrkarounds, $wrkaroundoptions);
             break;
         case 'itemid':
         default:
             $ret = $cache->get(array($cacheparams->class, $cacheparams->method), $cacheparams->methodparams, $module->id . $view_levels . \Request::getVar('Itemid', null, 'default', 'INT'), $wrkarounds, $wrkaroundoptions);
             break;
     }
     return $ret;
 }