Example #1
0
 /**
  * Returns contents of general (global) cache.
  * If the cache file tmp/cache/tracker/general.php does not exist yet, create it
  *
  * @return array
  */
 public static function getCacheGeneral()
 {
     $cache = self::getCache();
     $cacheContent = $cache->fetch(self::$cacheIdGeneral);
     if (false !== $cacheContent) {
         return $cacheContent;
     }
     Tracker::initCorePiwikInTrackerMode();
     $cacheContent = array('isBrowserTriggerEnabled' => Rules::isBrowserTriggerEnabled(), 'lastTrackerCronRun' => Option::get('lastTrackerCronRun'));
     /**
      * Triggered before the [general tracker cache](/guides/all-about-tracking#the-tracker-cache)
      * is saved to disk. This event can be used to add extra content to the cache.
      *
      * Data that is used during tracking but is expensive to compute/query should be
      * cached to keep tracking efficient. One example of such data are options
      * that are stored in the piwik_option table. Querying data for each tracking
      * request means an extra unnecessary database query for each visitor action. Using
      * a cache solves this problem.
      *
      * **Example**
      *
      *     public function setTrackerCacheGeneral(&$cacheContent)
      *     {
      *         $cacheContent['MyPlugin.myCacheKey'] = Option::get('MyPlugin_myOption');
      *     }
      *
      * @param array &$cacheContent Array of cached data. Each piece of data must be
      *                             mapped by name.
      */
     Piwik::postEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent));
     self::setCacheGeneral($cacheContent);
     Common::printDebug("General tracker cache was re-created.");
     Tracker::restoreTrackerPlugins();
     return $cacheContent;
 }