mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding Xcache support http://trac.lighttpd.net/xcache/
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4947 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
6a5f623240
commit
d029a776b7
2 changed files with 154 additions and 1 deletions
|
@ -178,6 +178,12 @@
|
|||
* APC (Alternative PHP Cache)
|
||||
* $cakeCache = array('APC');
|
||||
*
|
||||
* Xcache (PHP opcode cacher)
|
||||
* $cakeCache = array('Xcache', array(
|
||||
* 'user' => 'admin', // user from xcache.admin.user settings
|
||||
* 'password' => 'your_password', // plaintext password (xcache.admin.pass)
|
||||
* ));
|
||||
*
|
||||
* Memcache
|
||||
* $cakeCache = array('Memcache', [optional]array(
|
||||
* 'servers' => array(
|
||||
|
|
147
cake/libs/cache/xcache.php
vendored
Normal file
147
cake/libs/cache/xcache.php
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* Xcache storage engine for cache.
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.cache
|
||||
* @since CakePHP(tm) v 1.2.0.4947
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* Xcache storage engine for cache
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.cache
|
||||
*/
|
||||
class XcacheEngine extends CacheEngine {
|
||||
/**
|
||||
* Admin username (xcache.admin.user)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_php_auth_user = '';
|
||||
/**
|
||||
* Plaintext password for basic auth (xcache.admin.pass)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_php_auth_pw = '';
|
||||
/**
|
||||
* Set up the cache engine
|
||||
*
|
||||
* Called automatically by the cache frontend
|
||||
*
|
||||
* @param array $params Associative array of parameters for the engine
|
||||
* @return boolean True if the engine has been succesfully initialized, false if not
|
||||
*/
|
||||
function init($params) {
|
||||
$this->_php_auth_user = $params['user'];
|
||||
$this->_php_auth_pw = $params['password'];
|
||||
return function_exists('xcache_info');
|
||||
}
|
||||
/**
|
||||
* Write a value in the cache
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @param mixed $value Data to be cached
|
||||
* @param int $duration How long to cache the data, in seconds
|
||||
* @return boolean True if the data was succesfully cached, false on failure
|
||||
*/
|
||||
function write($key, &$value, $duration = CACHE_DEFAULT_DURATION) {
|
||||
return xcache_set($key, $value, $duration);
|
||||
}
|
||||
/**
|
||||
* Read a value from the cache
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
|
||||
*/
|
||||
function read($key) {
|
||||
if(xcache_isset($key)) {
|
||||
return xcache_get($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Delete a value from the cache
|
||||
*
|
||||
* @param string $key Identifier for the data
|
||||
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
|
||||
*/
|
||||
function delete($key) {
|
||||
return xcache_unset($key);
|
||||
}
|
||||
/**
|
||||
* Delete all values from the cache
|
||||
*
|
||||
* @return boolean True if the cache was succesfully cleared, false otherwise
|
||||
*/
|
||||
function clear() {
|
||||
$result = true;
|
||||
$this->_phpAuth();
|
||||
|
||||
for($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
|
||||
if(!xcache_clear_cache(XC_TYPE_VAR, $i)) {
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_phpAuth(true);
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Return the settings for this cache engine
|
||||
*
|
||||
* @return array list of settings for this engine
|
||||
*/
|
||||
function settings() {
|
||||
return array('class' => get_class($this));
|
||||
}
|
||||
/**
|
||||
* Makes necessary changes (and reverting them back) in $_SERVER
|
||||
*
|
||||
* This has to be done because xcache_clear_cache() needs pass Basic Auth
|
||||
* (see xcache.admin configuration settings)
|
||||
*/
|
||||
function _phpAuth($reverse = false) {
|
||||
static $backup = array();
|
||||
$keys = array('PHP_AUTH_USER', 'PHP_AUTH_PW');
|
||||
|
||||
foreach($keys as $key) {
|
||||
if($reverse) {
|
||||
if(isset($backup[$key])) {
|
||||
$_SERVER[$key] = $backup[$key];
|
||||
unset($backup[$key]);
|
||||
} else {
|
||||
unset($_SERVER[$key]);
|
||||
}
|
||||
} else {
|
||||
$value = env($key);
|
||||
if(!empty($value)) {
|
||||
$backup[$key] = $value;
|
||||
}
|
||||
$varName = '_' . low($key);
|
||||
$_SERVER[$key] = $this->{$varName};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue