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 cache_get_data($key, $ttl = 120) { global $boardurl, $sourcedir, $modSettings, $memcached; global $cache_hits, $cache_count, $db_show_debug; if (empty($modSettings['cache_enable']) && !empty($modSettings)) { return; } $cache_count = isset($cache_count) ? $cache_count + 1 : 1; if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get'); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . $key; // Okay, let's go for it memcached! if (function_exists('memcache_get') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return; } $value = memcache_get($memcached, $key); } elseif (function_exists('eaccelerator_get')) { $value = eaccelerator_get($key); } elseif (function_exists('mmcache_get')) { $value = mmcache_get($key); } elseif (function_exists('apc_fetch')) { $value = apc_fetch($key . 'smf'); } elseif (function_exists('output_cache_get')) { $value = output_cache_get($key, $ttl); } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0; } if (empty($value)) { return null; } else { return @unserialize($value); } }
/** * Clean some cache records * * Available modes are : * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * This mode is not supported in this backend * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * This mode is not supported in this backend * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not matching one of the given tags * ($tags can be an array of strings or a single string) * This mode is not supported in this backend * * @param string $mode clean mode * @param tags array $tags array of tags * @return boolean true if no problem */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { if ($mode == Zend_Cache::CLEANING_MODE_MATCHING_TAG) { $idlist = null; foreach ($tags as $tag) { $next_idlist = output_cache_get(self::TAGS_PREFIX . $tag, $this->_directives['lifetime']); if ($idlist) { $idlist = array_intersect_assoc($idlist, $next_idlist); } else { $idlist = $next_idlist; } if (count($idlist) == 0) { // if ID list is already empty - we may skip checking other IDs $idlist = null; break; } } if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } return true; } if ($mode == Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) { $this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend"); } $cache_dir = ini_get('zend_accelerator.output_cache_dir'); if (!$cache_dir) { return false; } $cache_dir .= '/.php_cache_api/'; return $this->_clean($cache_dir, $mode); }
/** * Get data from the cache * * Get data from the cache that matches this key, if it exists * * @param string $key the cache data identifier * @param int $ttl how long will the data be considered fresh (in seconds) * @return mixed $value the cache data or null * @since 0.1.0 */ function smfapi_cacheGetData($key, $ttl = 120) { global $boardurl, $sourcedir, $modSettings, $memcached; global $cache_hits, $cache_count, $db_show_debug, $cachedir; if (empty($modSettings['cache_enable']) && !empty($modSettings)) { return; } $cache_count = isset($cache_count) ? $cache_count + 1 : 1; if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get'); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':', '-'); // again, eAccelerator. if (function_exists('eaccelerator_get')) { $value = eaccelerator_get($key); } elseif (function_exists('mmcache_get')) { $value = mmcache_get($key); } elseif (function_exists('apc_fetch')) { $value = apc_fetch($key . 'smf'); } elseif (function_exists('output_cache_get')) { $value = output_cache_get($key, $ttl); } elseif (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) { $value = xcache_get($key); } elseif (file_exists($cachedir . '/data_' . $key . '.php') && filesize($cachedir . '/data_' . $key . '.php') > 10) { require $cachedir . '/data_' . $key . '.php'; if (!empty($expired) && isset($value)) { @unlink($cachedir . '/data_' . $key . '.php'); unset($value); } } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0; } if (empty($value)) { return null; } else { return @unserialize($value); } }
/** * Get a cached value. * * @param string $key * @param int $ttl = 120 */ public static function getCache($key, $ttl = 120) { if (-1 == self::$API) { return null; } self::$cache_count++; if (self::$want_debug) { self::$cache_hits[self::$cache_count] = array('k' => $key, 'd' => 'get'); $st = microtime(); } $key = self::$basekey . strtr($key, ':', '-'); switch (self::$API) { case 5: $key = str_replace(' ', '_', $key); $instance = self::getMemcachedServer(); $value = $instance->get($key); break; case 4: if (empty(self::$memcached)) { self::getMemcacheServer(); } if (!self::$memcached) { return; } $value = memcache_get(self::$memcached, $key); break; case 1: $value = apc_fetch($key . 'smf'); break; case 3: $value = output_cache_get($key, $ttl); break; case 2: $value = xcache_get($key); break; case 0: if (file_exists(self::$cachedir . '/data_' . $key . '.php') && filesize(self::$cachedir . '/data_' . $key . '.php') > 10) { require self::$cachedir . '/data_' . $key . '.php'; if (!empty($expired) && isset($value)) { @unlink(self::$cachedir . '/data_' . $key . '.php'); unset($value); } } break; } if (isset($db_show_debug) && $db_show_debug === true) { self::$cache_hits[self::$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); self::$cache_hits[self::$cache_count]['s'] = isset($value) ? strlen($value) : 0; } if (empty($value)) { return null; } else { return @unserialize($value); } }
/** * Load a cache file. * * @return mixed */ public function load() { $this->clean(); $content = output_cache_get($this->getIdMd5(), $this->_parameters->getParameter('lifetime')); if (isset($return[0])) { return $return[0]; } return false; }
/** * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. * - It may often "miss", so shouldn't be depended on. * - It supports the same as cache_put_data(). * * @param string $key * @param int $ttl = 120 */ function cache_get_data($key, $ttl = 120) { global $cache_memcached, $memcached, $cache_hits, $cache_count, $db_show_debug; global $cache_accelerator, $cache_enable, $expired; if (empty($cache_enable)) { return; } $cache_count = isset($cache_count) ? $cache_count + 1 : 1; if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get'); $st = microtime(true); } $key = cache_get_key($key); switch ($cache_accelerator) { case 'memcached': // Okay, let's go for it memcached! if ((function_exists('memcache_get') || function_exists('memcached_get')) && !empty($cache_memcached)) { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return null; } $value = function_exists('memcache_get') ? memcache_get($memcached, $key) : memcached_get($memcached, $key); } break; case 'eaccelerator': // Again, eAccelerator. if (function_exists('eaccelerator_get')) { $value = eaccelerator_get($key); } break; case 'mmcache': // The older, but ever-stable, Turck MMCache... if (function_exists('mmcache_get')) { $value = mmcache_get($key); } break; case 'apc': case 'apcu': // This is the free APC or APCu from PECL. if (function_exists('apc_fetch')) { $value = apc_fetch($key . 'elkarte'); } break; case 'zend': // Zend's pricey stuff. if (function_exists('zend_shm_cache_fetch')) { $value = zend_shm_cache_fetch('ELK::' . $key); } elseif (function_exists('output_cache_get')) { $value = output_cache_get($key, $ttl); } break; case 'xcache': if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) { $value = xcache_get($key); } break; default: // Otherwise it's ElkArte data! if (file_exists(CACHEDIR . '/data_' . $key . '.php') && filesize(CACHEDIR . '/data_' . $key . '.php') > 10) { // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution @(include CACHEDIR . '/data_' . $key . '.php'); if (!empty($expired) && isset($value)) { @unlink(CACHEDIR . '/data_' . $key . '.php'); unset($value); } } break; } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = microtime(true) - $st; $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0; } if (function_exists('call_integration_hook') && isset($value)) { call_integration_hook('cache_get_data', array($key, $ttl, $value)); } return empty($value) ? null : @unserialize($value); }
/** * Fetch data and timestamp from ZendPlatform, store in instance * * @param string $id * * @return bool success */ private function _fetch($id) { if ($this->_id === $id) { return true; } $ret = output_cache_get($id, $this->_exp); if (false === $ret) { $this->_id = null; return false; } list($this->_lm, $this->_data) = explode('|', $ret, 2); $this->_id = $id; return true; }
/** * Clean some cache records * * Available modes are : * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * This mode is not supported in this backend * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags * ($tags can be an array of strings or a single string) * * @param string $mode Clean mode * @param array $tags Array of tags * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean True if no problem */ public function clean($mode = IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { switch ($mode) { case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD: $cache_dir = ini_get('zend_accelerator.output_cache_dir'); if (!$cache_dir) { return false; } $cache_dir .= '/.php_cache_api/'; return $this->_clean($cache_dir, $mode); break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG: $idlist = null; foreach ($tags as $tag) { $next_idlist = output_cache_get(self::TAGS_PREFIX . $tag, $this->_directives['lifetime']); if ($idlist) { $idlist = array_intersect_assoc($idlist, $next_idlist); } else { $idlist = $next_idlist; } if (count($idlist) == 0) { // if ID list is already empty - we may skip checking other IDs $idlist = null; break; } } if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } return true; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: $this->_log("IfwPsn_Vendor_Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend"); return false; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $idlist = null; foreach ($tags as $tag) { $next_idlist = output_cache_get(self::TAGS_PREFIX . $tag, $this->_directives['lifetime']); if ($idlist) { $idlist = array_merge_recursive($idlist, $next_idlist); } else { $idlist = $next_idlist; } if (count($idlist) == 0) { // if ID list is already empty - we may skip checking other IDs $idlist = null; break; } } if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } return true; break; default: IfwPsn_Vendor_Zend_Cache::throwException('Invalid mode for clean() method'); break; } }
function pmxCacheGet($key, $useMember = false, $null_array = false) { global $PortaMx_cache, $user_info; $st = microtime(true); $key = $PortaMx_cache['key'] . ($useMember ? '-' . implode('_', $user_info['groups']) : '') . '-' . $key; if (function_exists('zend_shm_cache_fetch')) { $value = zend_shm_cache_fetch('PMX::' . $key); } elseif (function_exists('output_cache_get')) { $value = output_cache_get($key, $ttl); } if (!empty($value)) { $PortaMx_cache['vals']['loaded'] += strlen($value); $PortaMx_cache['vals']['time'] += microtime(true) - $st; return unserialize($value); } $PortaMx_cache['vals']['time'] += microtime(true) - $st; return empty($null_array) ? null : array(); }
/** * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. * - It may often "miss", so shouldn't be depended on. * - It supports the same as cache_put_data(). * * @param string $key * @param int $ttl = 120 * @return string */ function cache_get_data($key, $ttl = 120) { global $boardurl, $sourcedir, $modSettings, $memcached; global $cache_hits, $cache_count, $db_show_debug, $cachedir; global $cache_accelerator, $cache_enable; if (empty($cache_enable)) { return; } $cache_count = isset($cache_count) ? $cache_count + 1 : 1; if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count] = array('k' => $key, 'd' => 'get'); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':/', '-_'); switch ($cache_accelerator) { case 'memcache': // Okay, let's go for it memcached! if ((function_exists('memcache_get') || function_exists('memcached_get')) && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return null; } $value = function_exists('memcache_get') ? memcache_get($cache['connection'], $key) : memcached_get($cache['connection'], $key); } break; case 'eaccelerator': // Again, eAccelerator. if (function_exists('eaccelerator_get')) { $value = eaccelerator_get($key); } break; case 'mmcache': // The older, but ever-stable, Turck MMCache... if (function_exists('mmcache_get')) { $value = mmcache_get($key); } break; case 'apc': // This is the free APC from PECL. if (function_exists('apc_fetch')) { $value = apc_fetch($key . 'smf'); } break; case 'zend': // Zend's pricey stuff. if (function_exists('zend_shm_cache_fetch')) { $value = zend_shm_cache_fetch('SMF::' . $key, $ttl); } elseif (function_exists('output_cache_get')) { $value = output_cache_get($key, $ttl); } break; case 'xcache': if (function_exists('xcache_get') && ini_get('xcache.var_size') > 0) { $value = xcache_get($key); } break; default: // Otherwise it's SMF data! if (file_exists($cachedir . '/data_' . $key . '.php') && filesize($cachedir . '/data_' . $key . '.php') > 10) { // php will cache file_exists et all, we can't 100% depend on its results so proceed with caution @(include $cachedir . '/data_' . $key . '.php'); if (!empty($expired) && isset($value)) { @unlink($cachedir . '/data_' . $key . '.php'); unset($value); } } break; } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); $cache_hits[$cache_count]['s'] = isset($value) ? strlen($value) : 0; } if (function_exists('call_integration_hook')) { call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); } return empty($value) ? null : @unserialize($value); }
/** * Clean some cache records * * Available modes are : * Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * This mode is not supported in this backend * Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * This mode is not supported in this backend * Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not matching one of the given tags * ($tags can be an array of strings or a single string) * This mode is not supported in this backend * * @param string $mode clean mode * @param tags array $tags array of tags * @return boolean true if no problem */ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { if ($mode == Zend_Cache::CLEANING_MODE_MATCHING_TAG) { foreach ($tags as $tag) { $idlist = output_cache_get(self::TAGS_PREFIX . $tag); if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } } return true; } if ($mode == Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG) { if ($this->_directives['logging']) { Zend_Log::log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend", Zend_Log::LEVEL_WARNING); } } $cacheDir = ini_get('zend_accelerator.output_cache_dir'); if (!$cacheDir) { return false; } $cacheDir .= '/.php_cache_api/'; return $this->_clean($cacheDir, $mode); }
/** * Internal -- This function actually retrieves information from the caches. * It is a helper function that provides that actual cache API abstraction. * * @param unknown_type $key * @return unknown */ function external_cache_retrieve_helper($key) { $GLOBALS['external_cache_request_external_total']++; $value = null; if ($GLOBALS['external_cache_type'] == 'zend') { $value = output_cache_get($key, EXTERNAL_CACHE_INTERVAL_SECONDS); } elseif ($GLOBALS['external_cache_type'] == 'apc') { $value = apc_fetch($key); if (EXTERNAL_CACHE_DEBUG) { echo "<HR>retrieving key from cache ({$key}) value: ({$value})<HR>"; } } return $value; }