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"); } }
/** * 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"; } }
/** * Internal -- Determine if there is an external cache available for use. * Currently only Zend Platform is supported. */ function check_cache() { if (EXTERNAL_CACHE_DEBUG) { SugarCache::log("Checking cache"); } if ($GLOBALS['external_cache_checked'] == false) { $GLOBALS['external_cache_checked'] = true; $GLOBALS['external_cache_object'] = SugarCache::discover(); } if (EXTERNAL_CACHE_DEBUG) { SugarCache::log("Checking cache: " . var_export($GLOBALS['external_cache_enabled'], true)); } }
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; }
/** * 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); } } }