init
This commit is contained in:
220
include/utils/external_cache/SugarCache.php
Executable file
220
include/utils/external_cache/SugarCache.php
Executable file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache
|
||||
{
|
||||
/**
|
||||
* Discover and return available cache adapter of false if nothing is available
|
||||
*
|
||||
* @return SugarCache_Abstract|false
|
||||
*/
|
||||
function discover()
|
||||
{
|
||||
// If the cache is manually disabled, turn it off.
|
||||
if(!empty($GLOBALS['sugar_config']['external_cache_disabled']) && true == $GLOBALS['sugar_config']['external_cache_disabled'])
|
||||
{
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("SugarCache::discover() -- caching explicitly disabled", 'fail');
|
||||
}
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
return SugarCache::factory('Base');
|
||||
}
|
||||
|
||||
// check for Zend caching
|
||||
if(function_exists("output_cache_get") && empty($GLOBALS['sugar_config']['external_cache_disabled_zend']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "zend";
|
||||
$cache = SugarCache::factory('Zend');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found Zend - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif (extension_loaded('memcache') && empty($GLOBALS['sugar_config']['external_cache_disabled_memcache'])) {
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = 'memcache';
|
||||
$cache = SugarCache::factory('Memcache');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found memcache - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("apc_store") && empty($GLOBALS['sugar_config']['external_cache_disabled_apc']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "apc";
|
||||
$cache = SugarCache::factory('APC');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found APC - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("wincache_ucache_set") && empty($GLOBALS['sugar_config']['external_cache_disabled_wincache']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "wincache";
|
||||
$cache = SugarCache::factory('Wincache');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found Wincache - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("zget") && empty($GLOBALS['sugar_config']['external_cache_disabled_smash']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "smash";
|
||||
$cache = SugarCache::factory('sMash');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found sMash - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
// @todo memcache
|
||||
// @todo file cache as fallback
|
||||
else
|
||||
{
|
||||
// no cache available....return
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = 'base-in-memory';
|
||||
$cache = SugarCache::factory('Base');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found no caching solution - using base');
|
||||
}
|
||||
}
|
||||
|
||||
// Check the cache.
|
||||
if(!$cache->initialized)
|
||||
{
|
||||
// Validation failed. Turn off the external cache and return SugarCache_Base
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("external cache validation check failed...tried cache {$GLOBALS['external_cache_type']}", 'fail');
|
||||
SugarCache::log('returning Base');
|
||||
}
|
||||
return SugarCache::factory('Base');
|
||||
}
|
||||
|
||||
// If the cache is being reset, turn it off for this round trip
|
||||
$value = '';
|
||||
if(isset($GLOBALS['sugar_config']) && isset($GLOBALS['sugar_config']['unique_key']))
|
||||
{
|
||||
$value = $cache->get($GLOBALS['sugar_config']['unique_key'].'EXTERNAL_CACHE_RESET');
|
||||
}
|
||||
if(!empty($value))
|
||||
{
|
||||
// We are in a cache reset, do not use the cache.
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add one to the external cache hits. This will keep the end user statistics simple.
|
||||
// All real checks suceeding will result in 100%. Otherwise people will be looking for
|
||||
// the one check that did not pass.
|
||||
$GLOBALS['external_cache_request_external_hits']++;
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
function factory($type)
|
||||
{
|
||||
$class = 'SugarCache_' . $type;
|
||||
$cache = new $class();
|
||||
$cache->init();
|
||||
return $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs basic logging for messages generated by the external caching mechanism
|
||||
*
|
||||
* Currently this only outputs directly to the screen as it's only used internally.
|
||||
*
|
||||
* There are five supported $type values:
|
||||
* neutral :: just a log message with information value
|
||||
* pass :: a pass that attention should be brought to
|
||||
* lightpass :: a pass without much consequence
|
||||
* fail :: a fail that attention should be brought to
|
||||
* lightfail :: a failure without much consequence, or one that might succeed later in
|
||||
* the execution chain
|
||||
*
|
||||
* @param string $msg Message to output. Note it will be filtered through htmlspecialchars()
|
||||
* @param string $type Type of message to output
|
||||
*/
|
||||
function log($msg, $type = 'neutral') {
|
||||
static $messages = array();
|
||||
static $valid_types = array(
|
||||
'neutral' => '',
|
||||
'pass' => '',
|
||||
'lightpass' => '',
|
||||
'fail' => '',
|
||||
'lightfail' => '',
|
||||
);
|
||||
|
||||
if (!isset($valid_types[$type])) {
|
||||
SugarCache::log("Invalid type provided: {$type}", 'fail');
|
||||
$type = 'neutral';
|
||||
}
|
||||
$session_id = session_id();
|
||||
if (empty($session_id)) {
|
||||
// add to stack of messages to output after the session starts so we don't kill the headers
|
||||
$messages[] = array(
|
||||
'message' => htmlspecialchars($msg),
|
||||
'type' => $type,
|
||||
);
|
||||
} else {
|
||||
if ($messages !== false) {
|
||||
// output base styles on first round trip - this doesn't worry that its
|
||||
// not in the proper place as its for debugging purposes only.
|
||||
echo "<style type='text/css'>"
|
||||
. "hr +span { padding:3px 5px; display:block; } "
|
||||
. "hr +.pass { background-color:green; color: white; } "
|
||||
. "hr +.lightpass { background-color: #CFC; color:black; }"
|
||||
. "hr +.fail { background-color:red; color:white; } "
|
||||
. "hr +.lightfail { background-color:#F99; color: black; }"
|
||||
. "hr +.neutral { background-color:#FFFFE0; color:black; } "
|
||||
. "</style>";
|
||||
}
|
||||
if ($messages !== false && count($messages) > 0) {
|
||||
// clear stack of messages;
|
||||
echo '<hr />Messages logged prior to session starting...<hr />', "\n";
|
||||
foreach ($messages as $id => $old_msg) {
|
||||
echo "<hr /><span class='{$old_msg['type']}'>{$id} -- {$old_msg['message']}</span><hr />\n";
|
||||
}
|
||||
echo "<hr />End of messages prior to session starting...<hr />\n";
|
||||
}
|
||||
$messages = false;
|
||||
$msg = htmlspecialchars($msg);
|
||||
echo "<hr /><span class='{$type}'>{$msg}</span><hr />\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
95
include/utils/external_cache/SugarCache_APC.php
Executable file
95
include/utils/external_cache/SugarCache_APC.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache_APC extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via apc_fetch(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
apc_fetch(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
apc_store($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to APC cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
apc_delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
142
include/utils/external_cache/SugarCache_Base.php
Executable file
142
include/utils/external_cache/SugarCache_Base.php
Executable file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* The Base adapter only stores values in-memory.
|
||||
*
|
||||
* Cache adapters can extend this class in order to acheive local, in-memory
|
||||
* caching to reduce the number of round trips to outside caching mechanisms
|
||||
* during a single request.
|
||||
*
|
||||
*/
|
||||
class SugarCache_Base
|
||||
{
|
||||
/**
|
||||
* The status of this object
|
||||
* - null if init() has not been called
|
||||
* - false if init() failed
|
||||
* - true if init() succeeded
|
||||
*
|
||||
* @var null|bool
|
||||
* @access public
|
||||
*/
|
||||
var $initialized = null;
|
||||
|
||||
/**
|
||||
* Contains an in-memory cache of values in the cache
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_cache = array();
|
||||
|
||||
var $_my_class_name = '';
|
||||
|
||||
/**
|
||||
* Handle any initialization.
|
||||
*
|
||||
* @internal As shown here, at a minimum init() is responsible for flagging
|
||||
* the {@link $initialized} property to true on success.
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->initialized = true;
|
||||
$this->_my_class_name = strtolower(get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a given key/value pair within the cache
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
function set($key, $value)
|
||||
{
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 1: Adding key to {$GLOBALS['external_cache_type']} cache $key with value ($value)");
|
||||
}
|
||||
|
||||
if(empty($value)) {
|
||||
$value = EXTERNAL_CACHE_NULL_VALUE;
|
||||
}
|
||||
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 2: Adding key to {$GLOBALS['external_cache_type']} cache $key with value ($value)");
|
||||
}
|
||||
|
||||
$this->_cache[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value of a given key
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
function get($key)
|
||||
{
|
||||
$GLOBALS['external_cache_request_local_total']++;
|
||||
if (isset($this->_cache[$key])) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("BASE: found {$key}", 'lightpass');
|
||||
}
|
||||
$GLOBALS['external_cache_request_local_hits']++;
|
||||
return $this->_cache[$key];
|
||||
} else {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
$type = $this->_my_class_name == 'sugarcache_base' ? 'fail' : 'lightfail';
|
||||
SugarCache::log("BASE: unable to locate {$key}", $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a given value
|
||||
*
|
||||
* @internal The term "unset" is a reserved word within PHP. This
|
||||
* opts for using the magic __unset() within PHP5 to enable
|
||||
* direct unset($cache->foo) calls. Due to BC considerations
|
||||
* with PHP 4, however, this method should be invoked
|
||||
* directly via $cache->__unset('foo');
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
function __unset($key)
|
||||
{
|
||||
unset($this->_cache[$key]);
|
||||
}
|
||||
}
|
||||
145
include/utils/external_cache/SugarCache_ExternalAbstract.php
Executable file
145
include/utils/external_cache/SugarCache_ExternalAbstract.php
Executable file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
class SugarCache_ExternalAbstract extends SugarCache_Base
|
||||
{
|
||||
/**
|
||||
* Use the parent of object to attempt to retrieve cache? i.e., use local
|
||||
* memory cache.
|
||||
*
|
||||
* @var bool
|
||||
* @access protected
|
||||
*/
|
||||
var $_use_parent = true;
|
||||
|
||||
/**
|
||||
* An internal value that can be used to adjust the length of a timeout.
|
||||
*
|
||||
* If not set prior to calling {@link init()}, this will default to the constant
|
||||
* EXTERNAL_CACHE_INTERVAL_SECONDS
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $timeout = null;
|
||||
|
||||
/**
|
||||
* Stores the cache name
|
||||
* @access private
|
||||
*/
|
||||
var $_name = '';
|
||||
|
||||
/**
|
||||
* Serves to initialize this cache
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
if (empty($this->_timeout)) {
|
||||
$this->timeout = EXTERNAL_CACHE_INTERVAL_SECONDS;
|
||||
}
|
||||
|
||||
$this->_use_parent = false;
|
||||
|
||||
$value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
|
||||
if ($value != EXTERNAL_CACHE_WORKING_CHECK_KEY) {
|
||||
$this->set(
|
||||
EXTERNAL_CACHE_WORKING_CHECK_KEY,
|
||||
EXTERNAL_CACHE_WORKING_CHECK_KEY
|
||||
);
|
||||
$value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
|
||||
|
||||
// Clear the cache statistics after the test. This makes the statistics work out.
|
||||
$GLOBALS['external_cache_request_external_hits'] = 0;
|
||||
$GLOBALS['external_cache_request_external_total'] = 0;
|
||||
}
|
||||
|
||||
$this->_use_parent = true;
|
||||
$this->initialized = (EXTERNAL_CACHE_WORKING_CHECK_KEY == $value);
|
||||
|
||||
if (empty($this->_name)) {
|
||||
$this->_name = substr(get_class($this), 11);
|
||||
}
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
if ($this->_use_parent && !is_null($value = parent::get($key))) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: found {$key} in local memory cache");
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: caching disabled", 'fail');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
$GLOBALS['external_cache_request_external_total']++;
|
||||
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: retrieving key from cache ($key)");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function _realKey($key)
|
||||
{
|
||||
return $GLOBALS['sugar_config']['unique_key'] . $key;
|
||||
}
|
||||
|
||||
function _processGet($key, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: Retrieved from external cache: {$key}", 'pass');
|
||||
}
|
||||
$GLOBALS['external_cache_request_external_hits']++;
|
||||
$this->_cache[$key] = $value;
|
||||
return $this->_cache[$key];
|
||||
}
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: External cache retrieve failed: $key", 'fail');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
117
include/utils/external_cache/SugarCache_Memcache.php
Executable file
117
include/utils/external_cache/SugarCache_Memcache.php
Executable file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache_Memcache extends SugarCache_ExternalAbstract
|
||||
{
|
||||
var $_memcache = null;
|
||||
var $_config = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 11211,
|
||||
);
|
||||
|
||||
function SugarCache_Memcache()
|
||||
{
|
||||
$config = SugarConfig::getInstance();
|
||||
$this->_config['host'] = $config->get('external_cache.memcache.host', 'localhost');
|
||||
$this->_config['port'] = $config->get('external_cache.memcache.port', 11211);
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('initializing memcache');
|
||||
}
|
||||
$this->_memcache = new Memcache();
|
||||
$status = @$this->_memcache->connect(
|
||||
$this->_config['host'],
|
||||
$this->_config['port']
|
||||
);
|
||||
if (!$status) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('initialization of memcache failed', 'fail');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via Memcache::get(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
$this->_memcache->get(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
$this->_memcache->set($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to memcache cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
$this->_memcache->delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
|
||||
95
include/utils/external_cache/SugarCache_Wincache.php
Executable file
95
include/utils/external_cache/SugarCache_Wincache.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache_Wincache extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via wincache_ucache_get(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
wincache_ucache_get(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
wincache_ucache_set($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to Wincache cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
wincache_ucache_delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
86
include/utils/external_cache/SugarCache_Zend.php
Executable file
86
include/utils/external_cache/SugarCache_Zend.php
Executable file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache_Zend extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$raw_cache_value = output_cache_get(
|
||||
$this->_realKey($key),
|
||||
$this->timeout
|
||||
);
|
||||
$cache_value = is_string($raw_cache_value) ?
|
||||
unserialize($raw_cache_value) :
|
||||
$raw_cache_value;
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
$cache_value
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
output_cache_put($external_key, serialize($value));
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to Zend cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
output_cache_remove_key($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
101
include/utils/external_cache/SugarCache_sMash.php
Executable file
101
include/utils/external_cache/SugarCache_sMash.php
Executable file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
class SugarCache_sMash extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via zget(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
zget(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
zput($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to sMash cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function _realKey($key)
|
||||
{
|
||||
return '/tmp/'.$GLOBALS['sugar_config']['unique_key'] .'/'. $key;
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
zdelete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user