Source for file cache.php

Documentation is available at cache.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Plugin
  4.  * @subpackage  System.cache
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Joomla! Page Cache Plugin
  14.  *
  15.  * @package     Joomla.Plugin
  16.  * @subpackage  System.cache
  17.  */
  18. class PlgSystemCache extends JPlugin
  19. {
  20.  
  21.     var $_cache        = null;
  22.  
  23.     var $_cache_key    = null;
  24.  
  25.     /**
  26.      * Constructor
  27.      *
  28.      * @access    protected
  29.      * @param   object    $subject The object to observe
  30.      * @param   array  $config  An array that holds the plugin configuration
  31.      * @since   1.0
  32.      */
  33.     function __construct($subject$config)
  34.     {
  35.         parent::__construct($subject$config);
  36.  
  37.         //Set the language in the class
  38.         $options array(
  39.             'defaultgroup'    => 'page',
  40.             'browsercache'    => $this->params->get('browsercache'false),
  41.             'caching'        => false,
  42.         );
  43.  
  44.         $this->_cache        = JCache::getInstance('page'$options);
  45.         $this->_cache_key    = JUri::getInstance()->toString();
  46.     }
  47.  
  48.     /**
  49.     * Converting the site URL to fit to the HTTP request
  50.     *
  51.     */
  52.     function onAfterInitialise()
  53.     {
  54.         global $_PROFILER;
  55.  
  56.         $app  JFactory::getApplication();
  57.         $user JFactory::getUser();
  58.  
  59.         if ($app->isAdmin())
  60.         {
  61.             return;
  62.         }
  63.  
  64.         if (count($app->getMessageQueue()))
  65.         {
  66.             return;
  67.         }
  68.  
  69.         if ($user->get('guest'&& $app->input->getMethod(== 'GET')
  70.         {
  71.             $this->_cache->setCaching(true);
  72.         }
  73.  
  74.         $data $this->_cache->get($this->_cache_key);
  75.  
  76.         if ($data !== false)
  77.         {
  78.             // Set cached body
  79.             $app->setBody($data);
  80.  
  81.             echo $app->toString($app->getCfg('gzip'));
  82.  
  83.             if (JDEBUG)
  84.             {
  85.                 $_PROFILER->mark('afterCache');
  86.             }
  87.  
  88.             $app->close();
  89.         }
  90.     }
  91.  
  92.     function onAfterRender()
  93.     {
  94.         $app JFactory::getApplication();
  95.  
  96.         if ($app->isAdmin())
  97.         {
  98.             return;
  99.         }
  100.  
  101.         if (count($app->getMessageQueue()))
  102.         {
  103.             return;
  104.         }
  105.  
  106.         $user JFactory::getUser();
  107.         if ($user->get('guest'))
  108.         {
  109.             // We need to check again here, because auto-login plugins have not been fired before the first aid check
  110.             $this->_cache->store(null$this->_cache_key);
  111.         }
  112.     }
  113. }

Documentation generated on Tue, 19 Nov 2013 14:54:51 +0100 by phpDocumentor 1.4.3