Support Joomla!

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /joomla/cache/storage/eaccelerator.php

Documentation is available at eaccelerator.php

  1. <?php
  2. /**
  3.  * @version        $Id: eaccelerator.php 10707 2008-08-21 09:52:47Z eddieajau $
  4.  * @package        Joomla.Framework
  5.  * @subpackage    Cache
  6.  * @copyright    Copyright (C) 2005 - 2008 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. {
  26.     /**
  27.     * Constructor
  28.     *
  29.     * @access protected
  30.     * @param array $options optional parameters
  31.     */
  32.     function __construct$options array() )
  33.     {
  34.         parent::__construct($options);
  35.  
  36.         $config            =JFactory::getConfig();
  37.         $this->_hash    $config->getValue('config.secret');
  38.     }
  39.  
  40.     /**
  41.      * Get cached data by id and group
  42.      *
  43.      * @access    public
  44.      * @param    string    $id            The cache data id
  45.      * @param    string    $group        The cache data group
  46.      * @param    boolean    $checkTime    True to verify cache time expiration threshold
  47.      * @return    mixed    Boolean false on failure or a cached data string
  48.      * @since    1.5
  49.      */
  50.     function get($id$group$checkTime)
  51.     {
  52.         $cache_id $this->_getCacheId($id$group);
  53.         $this->_setExpire($cache_id);
  54.         $cache_content eaccelerator_get($cache_id);
  55.         if($cache_content === null)
  56.         {
  57.             return false;
  58.         }
  59.         return $cache_content;
  60.     }
  61.  
  62.     /**
  63.      * Store the data to by id and group
  64.      *
  65.      * @access    public
  66.      * @param    string    $id        The cache data id
  67.      * @param    string    $group    The cache data group
  68.      * @param    string    $data    The data to store in cache
  69.      * @return    boolean    True on success, false otherwise
  70.      * @since    1.5
  71.      */
  72.     function store($id$group$data)
  73.     {
  74.         $cache_id $this->_getCacheId($id$group);
  75.         eaccelerator_put($cache_id.'_expire'time());
  76.         return eaccelerator_put($cache_id$data$this->_lifetime);
  77.     }
  78.  
  79.     /**
  80.      * Remove a cached data entry by id and group
  81.      *
  82.      * @access    public
  83.      * @param    string    $id        The cache data id
  84.      * @param    string    $group    The cache data group
  85.      * @return    boolean    True on success, false otherwise
  86.      * @since    1.5
  87.      */
  88.     function remove($id$group)
  89.     {
  90.         $cache_id $this->_getCacheId($id$group);
  91.         eaccelerator_rm($cache_id.'_expire');
  92.         return eaccelerator_rm($cache_id);
  93.     }
  94.  
  95.     /**
  96.      * Clean cache for a group given a mode.
  97.      *
  98.      * group mode        : cleans all cache in the group
  99.      * notgroup mode    : cleans all cache not in the group
  100.      *
  101.      * @access    public
  102.      * @param    string    $group    The cache data group
  103.      * @param    string    $mode    The mode for cleaning cache [group|notgroup]
  104.      * @return    boolean    True on success, false otherwise
  105.      * @since    1.5
  106.      */
  107.     function clean($group$mode)
  108.     {
  109.         return true;
  110.     }
  111.  
  112.     /**
  113.      * Garbage collect expired cache data
  114.      *
  115.      * @access public
  116.      * @return boolean  True on success, false otherwise.
  117.      */
  118.     function gc()
  119.     {
  120.         return eaccelerator_gc();
  121.     }
  122.  
  123.     /**
  124.      * Test to see if the cache storage is available.
  125.      *
  126.      * @static
  127.      * @access public
  128.      * @return boolean  True on success, false otherwise.
  129.      */
  130.     function test()
  131.     {
  132.         return (extension_loaded('eaccelerator'&& function_exists('eaccelerator_get'));
  133.     }
  134.  
  135.     /**
  136.      * Set expire time on each call since memcache sets it on cache creation.
  137.      *
  138.      * @access private
  139.      *
  140.      * @param string  $key   Cache key to expire.
  141.      * @param integer $lifetime  Lifetime of the data in seconds.
  142.      */
  143.     function _setExpire($key)
  144.     {
  145.         $lifetime    $this->_lifetime;
  146.         $expire        eaccelerator_get($key.'_expire');
  147.  
  148.         // set prune period
  149.         if ($expire $lifetime time()) {
  150.             eaccelerator_rm($key);
  151.             eaccelerator_rm($key.'_expire');
  152.         else {
  153.             eaccelerator_put($key.'_expire',  time());
  154.         }
  155.     }
  156.  
  157.     /**
  158.      * Get a cache_id string from an id/group pair
  159.      *
  160.      * @access    private
  161.      * @param    string    $id        The cache data id
  162.      * @param    string    $group    The cache data group
  163.      * @return    string    The cache_id string
  164.      * @since    1.5
  165.      */
  166.     function _getCacheId($id$group)
  167.     {
  168.         $name    md5($this->_application.'-'.$id.'-'.$this->_hash.'-'.$this->_language);
  169.         return 'cache_'.$group.'-'.$name;
  170.     }
  171. }

Documentation generated on Mon, 22 Sep 2008 12:08:35 +0100 by phpDocumentor 1.3.1