[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/acm/ -> acm_eaccelerator.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package acm
   5  * @version $Id$
   6  * @copyright (c) 2005, 2009 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  // Include the abstract base
  20  if (!class_exists('acm_memory'))
  21  {
  22      require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
  23  }
  24  
  25  /**
  26  * ACM for eAccelerator
  27  * @package acm
  28  * @todo Missing locks from destroy() talk with David
  29  */
  30  class acm extends acm_memory
  31  {
  32      var $extension = 'eaccelerator';
  33      var $function = 'eaccelerator_get';
  34  
  35      var $serialize_header = '#phpbb-serialized#';
  36  
  37      /**
  38      * Purge cache data
  39      *
  40      * @return null
  41      */
  42  	function purge()
  43      {
  44          foreach (eaccelerator_list_keys() as $var)
  45          {
  46              // @todo Check why the substr()
  47              // @todo Only unset vars matching $this->key_prefix
  48              eaccelerator_rm(substr($var['name'], 1));
  49          }
  50  
  51          parent::purge();
  52      }
  53  
  54      /**
  55       * Perform cache garbage collection
  56       *
  57       * @return null
  58       */
  59  	function tidy()
  60      {
  61          eaccelerator_gc();
  62  
  63          set_config('cache_last_gc', time(), true);
  64      }
  65  
  66      /**
  67      * Fetch an item from the cache
  68      *
  69      * @access protected
  70      * @param string $var Cache key
  71      * @return mixed Cached data
  72      */
  73  	function _read($var)
  74      {
  75          $result = eaccelerator_get($this->key_prefix . $var);
  76  
  77          if ($result === null)
  78          {
  79              return false;
  80          }
  81  
  82          // Handle serialized objects
  83          if (is_string($result) && strpos($result, $this->serialize_header . 'O:') === 0)
  84          {
  85              $result = unserialize(substr($result, strlen($this->serialize_header)));
  86          }
  87  
  88          return $result;
  89      }
  90  
  91      /**
  92      * Store data in the cache
  93      *
  94      * @access protected
  95      * @param string $var Cache key
  96      * @param mixed $data Data to store
  97      * @param int $ttl Time-to-live of cached data
  98      * @return bool True if the operation succeeded
  99      */
 100  	function _write($var, $data, $ttl = 2592000)
 101      {
 102          // Serialize objects and make them easy to detect
 103          $data = (is_object($data)) ? $this->serialize_header . serialize($data) : $data;
 104  
 105          return eaccelerator_put($this->key_prefix . $var, $data, $ttl);
 106      }
 107  
 108      /**
 109      * Remove an item from the cache
 110      *
 111      * @access protected
 112      * @param string $var Cache key
 113      * @return bool True if the operation succeeded
 114      */
 115  	function _delete($var)
 116      {
 117          return eaccelerator_rm($this->key_prefix . $var);
 118      }
 119  }
 120  
 121  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1