[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/cache/storage/ -> eaccelerator.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: eaccelerator.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla.Framework
   5   * @subpackage    Cache
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * eAccelerator cache storage handler
  20   *
  21   * @package        Joomla.Framework
  22   * @subpackage    Cache
  23   * @since        1.5
  24   */
  25  class JCacheStorageEaccelerator extends JCacheStorage
  26  {
  27      /**
  28      * Constructor
  29      *
  30      * @access protected
  31      * @param array $options optional parameters
  32      */
  33  	function __construct( $options = array() )
  34      {
  35          parent::__construct($options);
  36  
  37          $config            =& JFactory::getConfig();
  38          $this->_hash    = $config->getValue('config.secret');
  39      }
  40  
  41      /**
  42       * Get cached data by id and group
  43       *
  44       * @access    public
  45       * @param    string    $id            The cache data id
  46       * @param    string    $group        The cache data group
  47       * @param    boolean    $checkTime    True to verify cache time expiration threshold
  48       * @return    mixed    Boolean false on failure or a cached data string
  49       * @since    1.5
  50       */
  51  	function get($id, $group, $checkTime)
  52      {
  53          $cache_id = $this->_getCacheId($id, $group);
  54          $this->_setExpire($cache_id);
  55          $cache_content = eaccelerator_get($cache_id);
  56          if($cache_content === null)
  57          {
  58              return false;
  59          }
  60          return $cache_content;
  61      }
  62  
  63      /**
  64       * Store the data to by id and group
  65       *
  66       * @access    public
  67       * @param    string    $id        The cache data id
  68       * @param    string    $group    The cache data group
  69       * @param    string    $data    The data to store in cache
  70       * @return    boolean    True on success, false otherwise
  71       * @since    1.5
  72       */
  73  	function store($id, $group, $data)
  74      {
  75          $cache_id = $this->_getCacheId($id, $group);
  76          eaccelerator_put($cache_id.'_expire', time());
  77          return eaccelerator_put($cache_id, $data, $this->_lifetime);
  78      }
  79  
  80      /**
  81       * Remove a cached data entry by id and group
  82       *
  83       * @access    public
  84       * @param    string    $id        The cache data id
  85       * @param    string    $group    The cache data group
  86       * @return    boolean    True on success, false otherwise
  87       * @since    1.5
  88       */
  89  	function remove($id, $group)
  90      {
  91          $cache_id = $this->_getCacheId($id, $group);
  92          eaccelerator_rm($cache_id.'_expire');
  93          return eaccelerator_rm($cache_id);
  94      }
  95  
  96      /**
  97       * Clean cache for a group given a mode.
  98       *
  99       * group mode        : cleans all cache in the group
 100       * notgroup mode    : cleans all cache not in the group
 101       *
 102       * @access    public
 103       * @param    string    $group    The cache data group
 104       * @param    string    $mode    The mode for cleaning cache [group|notgroup]
 105       * @return    boolean    True on success, false otherwise
 106       * @since    1.5
 107       */
 108  	function clean($group, $mode)
 109      {
 110          return true;
 111      }
 112  
 113      /**
 114       * Garbage collect expired cache data
 115       *
 116       * @access public
 117       * @return boolean  True on success, false otherwise.
 118       */
 119      function gc()
 120      {
 121          return eaccelerator_gc();
 122      }
 123  
 124      /**
 125       * Test to see if the cache storage is available.
 126       *
 127       * @static
 128       * @access public
 129       * @return boolean  True on success, false otherwise.
 130       */
 131  	function test()
 132      {
 133          return (extension_loaded('eaccelerator') && function_exists('eaccelerator_get'));
 134      }
 135  
 136      /**
 137       * Set expire time on each call since memcache sets it on cache creation.
 138       *
 139       * @access private
 140       *
 141       * @param string  $key   Cache key to expire.
 142       * @param integer $lifetime  Lifetime of the data in seconds.
 143       */
 144  	function _setExpire($key)
 145      {
 146          $lifetime    = $this->_lifetime;
 147          $expire        = eaccelerator_get($key.'_expire');
 148  
 149          // set prune period
 150          if ($expire + $lifetime < time()) {
 151              eaccelerator_rm($key);
 152              eaccelerator_rm($key.'_expire');
 153          } else {
 154              eaccelerator_put($key.'_expire',  time());
 155          }
 156      }
 157  
 158      /**
 159       * Get a cache_id string from an id/group pair
 160       *
 161       * @access    private
 162       * @param    string    $id        The cache data id
 163       * @param    string    $group    The cache data group
 164       * @return    string    The cache_id string
 165       * @since    1.5
 166       */
 167  	function _getCacheId($id, $group)
 168      {
 169          $name    = md5($this->_application.'-'.$id.'-'.$this->_hash.'-'.$this->_language);
 170          return 'cache_'.$group.'-'.$name;
 171      }
 172  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1