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 ""; } if ($messages !== false && count($messages) > 0) { // clear stack of messages; echo '
Messages logged prior to session starting...
', "\n"; foreach ($messages as $id => $old_msg) { echo "
{$id} -- {$old_msg['message']}
\n"; } echo "
End of messages prior to session starting...
\n"; } $messages = false; $msg = htmlspecialchars($msg); echo "
{$msg}
\n"; } } }