2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
42 class SugarCache_ExternalAbstract extends SugarCache_Base
45 * Use the parent of object to attempt to retrieve cache? i.e., use local
51 var $_use_parent = true;
54 * An internal value that can be used to adjust the length of a timeout.
56 * If not set prior to calling {@link init()}, this will default to the constant
57 * EXTERNAL_CACHE_INTERVAL_SECONDS
64 * Stores the cache name
70 * Serves to initialize this cache
74 if (empty($this->_timeout)) {
75 $this->timeout = EXTERNAL_CACHE_INTERVAL_SECONDS;
78 $this->_use_parent = false;
80 $value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
81 if ($value != EXTERNAL_CACHE_WORKING_CHECK_KEY) {
83 EXTERNAL_CACHE_WORKING_CHECK_KEY,
84 EXTERNAL_CACHE_WORKING_CHECK_KEY
86 $value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
88 // Clear the cache statistics after the test. This makes the statistics work out.
89 $GLOBALS['external_cache_request_external_hits'] = 0;
90 $GLOBALS['external_cache_request_external_total'] = 0;
93 $this->_use_parent = true;
94 $this->initialized = (EXTERNAL_CACHE_WORKING_CHECK_KEY == $value);
96 if (empty($this->_name)) {
97 $this->_name = substr(get_class($this), 11);
103 if ($this->_use_parent && !is_null($value = parent::get($key))) {
104 if (EXTERNAL_CACHE_DEBUG) {
105 SugarCache::log("{$this->_name}:: found {$key} in local memory cache");
110 if(!$GLOBALS['external_cache_enabled']) {
111 if (EXTERNAL_CACHE_DEBUG) {
112 SugarCache::log("{$this->_name}:: caching disabled", 'fail');
117 $GLOBALS['external_cache_request_external_total']++;
119 if(EXTERNAL_CACHE_DEBUG) {
120 SugarCache::log("{$this->_name}:: retrieving key from cache ($key)");
126 function _realKey($key)
128 return $GLOBALS['sugar_config']['unique_key'] . $key;
131 function _processGet($key, $value)
133 if (!empty($value)) {
134 if (EXTERNAL_CACHE_DEBUG) {
135 SugarCache::log("{$this->_name}:: Retrieved from external cache: {$key}", 'pass');
137 $GLOBALS['external_cache_request_external_hits']++;
138 $this->_cache[$key] = $value;
139 return $this->_cache[$key];
141 if(EXTERNAL_CACHE_DEBUG) {
142 SugarCache::log("{$this->_name}:: External cache retrieve failed: $key", 'fail');