1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acm/acm_eaccelerator.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,121 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acm
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005, 2009 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +// Include the abstract base
1.23 +if (!class_exists('acm_memory'))
1.24 +{
1.25 + require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
1.26 +}
1.27 +
1.28 +/**
1.29 +* ACM for eAccelerator
1.30 +* @package acm
1.31 +* @todo Missing locks from destroy() talk with David
1.32 +*/
1.33 +class acm extends acm_memory
1.34 +{
1.35 + var $extension = 'eaccelerator';
1.36 + var $function = 'eaccelerator_get';
1.37 +
1.38 + var $serialize_header = '#phpbb-serialized#';
1.39 +
1.40 + /**
1.41 + * Purge cache data
1.42 + *
1.43 + * @return void
1.44 + */
1.45 + function purge()
1.46 + {
1.47 + foreach (eaccelerator_list_keys() as $var)
1.48 + {
1.49 + // @todo Check why the substr()
1.50 + // @todo Only unset vars matching $this->key_prefix
1.51 + eaccelerator_rm(substr($var['name'], 1));
1.52 + }
1.53 +
1.54 + parent::purge();
1.55 + }
1.56 +
1.57 + /**
1.58 + * Perform cache garbage collection
1.59 + *
1.60 + * @return void
1.61 + */
1.62 + function tidy()
1.63 + {
1.64 + eaccelerator_gc();
1.65 +
1.66 + set_config('cache_last_gc', time(), true);
1.67 + }
1.68 +
1.69 + /**
1.70 + * Fetch an item from the cache
1.71 + *
1.72 + * @access protected
1.73 + * @param string $var Cache key
1.74 + * @return mixed Cached data
1.75 + */
1.76 + function _read($var)
1.77 + {
1.78 + $result = eaccelerator_get($this->key_prefix . $var);
1.79 +
1.80 + if ($result === null)
1.81 + {
1.82 + return false;
1.83 + }
1.84 +
1.85 + // Handle serialized objects
1.86 + if (is_string($result) && strpos($result, $this->serialize_header . 'O:') === 0)
1.87 + {
1.88 + $result = unserialize(substr($result, strlen($this->serialize_header)));
1.89 + }
1.90 +
1.91 + return $result;
1.92 + }
1.93 +
1.94 + /**
1.95 + * Store data in the cache
1.96 + *
1.97 + * @access protected
1.98 + * @param string $var Cache key
1.99 + * @param mixed $data Data to store
1.100 + * @param int $ttl Time-to-live of cached data
1.101 + * @return bool True if the operation succeeded
1.102 + */
1.103 + function _write($var, $data, $ttl = 2592000)
1.104 + {
1.105 + // Serialize objects and make them easy to detect
1.106 + $data = (is_object($data)) ? $this->serialize_header . serialize($data) : $data;
1.107 +
1.108 + return eaccelerator_put($this->key_prefix . $var, $data, $ttl);
1.109 + }
1.110 +
1.111 + /**
1.112 + * Remove an item from the cache
1.113 + *
1.114 + * @access protected
1.115 + * @param string $var Cache key
1.116 + * @return bool True if the operation succeeded
1.117 + */
1.118 + function _delete($var)
1.119 + {
1.120 + return eaccelerator_rm($this->key_prefix . $var);
1.121 + }
1.122 +}
1.123 +
1.124 +?>
1.125 \ No newline at end of file