Source for file cache.php

Documentation is available at cache.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_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.  * Cache Model
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_cache
  17.  * @since       1.6
  18.  */
  19. class CacheModelCache extends JModelList
  20. {
  21.     /**
  22.      * An Array of CacheItems indexed by cache group ID
  23.      *
  24.      * @var Array 
  25.      */
  26.     protected $_data = array();
  27.  
  28.     /**
  29.      * Group total
  30.      *
  31.      * @var integer 
  32.      */
  33.     protected $_total = null;
  34.  
  35.     /**
  36.      * Pagination object
  37.      *
  38.      * @var object 
  39.      */
  40.     protected $_pagination = null;
  41.  
  42.     /**
  43.      * Method to auto-populate the model state.
  44.      *
  45.      * Note. Calling getState in this method will result in recursion.
  46.      *
  47.      * @since   1.6
  48.      */
  49.     protected function populateState($ordering null$direction null)
  50.     {
  51.         $clientId $this->getUserStateFromRequest($this->context.'.filter.client_id''filter_client_id'0'int');
  52.         $this->setState('clientId'$clientId == 0);
  53.  
  54.         $client    JApplicationHelper::getClientInfo($clientId);
  55.         $this->setState('client'$client);
  56.  
  57.         parent::populateState('group''asc');
  58.     }
  59.  
  60.     /**
  61.      * Method to get cache data
  62.      *
  63.      * @return array 
  64.      */
  65.     public function getData()
  66.     {
  67.         if (empty($this->_data))
  68.         {
  69.             $cache $this->getCache();
  70.             $data  $cache->getAll();
  71.  
  72.             if ($data != false)
  73.             {
  74.                 $this->_data = $data;
  75.                 $this->_total = count($data);
  76.  
  77.                 if ($this->_total)
  78.                 {
  79.                     // Apply custom ordering
  80.                     $ordering     $this->getState('list.ordering');
  81.                     $direction     ($this->getState('list.direction'== 'asc': -1;
  82.  
  83.                     jimport('joomla.utilities.arrayhelper');
  84.                     $this->_data = JArrayHelper::sortObjects($data$ordering$direction);
  85.  
  86.                     // Apply custom pagination
  87.                     if ($this->_total > $this->getState('list.limit'&& $this->getState('list.limit'))
  88.                     {
  89.                         $this->_data = array_slice($this->_data$this->getState('list.start')$this->getState('list.limit'));
  90.                     }
  91.                 }
  92.             else {
  93.                 $this->_data = array();
  94.             }
  95.         }
  96.         return $this->_data;
  97.     }
  98.  
  99.     /**
  100.      * Method to get cache instance
  101.      *
  102.      * @return object 
  103.      */
  104.     public function getCache()
  105.     {
  106.         $conf JFactory::getConfig();
  107.  
  108.         $options array(
  109.             'defaultgroup'    => '',
  110.             'storage'         => $conf->get('cache_handler'''),
  111.             'caching'        => true,
  112.             'cachebase'        => ($this->getState('clientId'== 1JPATH_ADMINISTRATOR '/cache' $conf->get('cache_path'JPATH_SITE '/cache')
  113.         );
  114.  
  115.         $cache JCache::getInstance(''$options);
  116.  
  117.         return $cache;
  118.     }
  119.  
  120.     /**
  121.      * Method to get client data
  122.      *
  123.      * @return array 
  124.      */
  125.     public function getClient()
  126.     {
  127.         return $this->getState('client');
  128.     }
  129.  
  130.     /**
  131.      * Get the number of current Cache Groups
  132.      *
  133.      * @return  int 
  134.      */
  135.     public function getTotal()
  136.     {
  137.         if (empty($this->_total))
  138.         {
  139.             $this->_total = count($this->getData());
  140.         }
  141.  
  142.         return $this->_total;
  143.     }
  144.  
  145.     /**
  146.      * Method to get a pagination object for the cache
  147.      *
  148.      * @return  integer 
  149.      */
  150.     public function getPagination()
  151.     {
  152.         if (empty($this->_pagination))
  153.         {
  154.             $this->_pagination = new JPagination($this->getTotal()$this->getState('list.start')$this->getState('list.limit'));
  155.         }
  156.  
  157.         return $this->_pagination;
  158.     }
  159.  
  160.     /**
  161.      * Clean out a cache group as named by param.
  162.      * If no param is passed clean all cache groups.
  163.      *
  164.      * @param String $group 
  165.      */
  166.     public function clean($group '')
  167.     {
  168.         $cache $this->getCache();
  169.         $cache->clean($group);
  170.     }
  171.  
  172.     public function cleanlist($array)
  173.     {
  174.         foreach ($array as $group)
  175.         {
  176.             $this->clean($group);
  177.         }
  178.     }
  179.  
  180.     public function purge()
  181.     {
  182.         $cache JFactory::getCache('');
  183.         return $cache->gc();
  184.     }
  185. }

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