/** * Disconnect from remote cache store * * @return @e boolean */ public function disconnect() { if (function_exists('eaccelerator_gc')) { eaccelerator_gc(); } return true; }
public function clean() { eaccelerator_clean(); eaccelerator_clear(); eaccelerator_gc(); eaccelerator_purge(); return; }
/** * Deletes all EAccelerator data cache */ public function flushAll() { //delete expired content then delete all eaccelerator_gc(); $idkeys = eaccelerator_list_keys(); foreach ($idkeys as $k) { $this->flush(substr($k['name'], 1)); } }
public function clear() { if (!CACHE_STATUS) { return false; } eaccelerator_gc(); foreach (eaccelerator_list_keys() as $key) { cache_delete_callback(substr($key["name"], 1)); } }
/** * 清空cache中所有项, 全部清除需要遍历cache,一个一个删除! * @return void * @access public */ public static function flush() { // 清除过期的key eaccelerator_gc(); // 遍历key,一个一个删除 $list = eaccelerator_list_keys(); foreach ($list as $k => $v) { self::delete($v['name']); } }
public function clear() { if (!_cacheStatus) { return FALSE; } eaccelerator_gc(); foreach (eaccelerator_list_keys() as $key) { cache_delete_callback(substr($key["name"], 1)); } }
public function flush() { // first, remove expired content from cache eaccelerator_gc(); // now, remove leftover cache-keys $keys = eaccelerator_list_keys(); foreach ($keys as $key) { $this->deleteValue(substr($key['name'], 1)); } }
/** * @see sfCache */ public function clean($mode = sfCache::ALL) { if (sfCache::OLD === $mode) { return eaccelerator_gc(); } $infos = eaccelerator_list_keys(); if (is_array($infos)) { foreach ($infos as $info) { if (false !== strpos($info['name'], $this->getOption('prefix'))) { // eaccelerator bug (http://eaccelerator.net/ticket/287) $key = 0 === strpos($info['name'], ':') ? substr($info['name'], 1) : $info['name']; if (!eaccelerator_rm($key)) { return false; } } } } return true; }
/** * {@inheritDoc} */ function tidy() { global $config; eaccelerator_gc(); $config->set('cache_last_gc', time(), false); }
public function delete_expired() { eaccelerator_gc(); }
/** * Garbage collect stale sessions from the SessionHandler backend. * * @access public * @param integer $maxlifetime The maximum age of a session. * @return boolean True on success, false otherwise. */ function gc($maxlifetime) { eaccelerator_gc(); return true; }
/** * Garbage collect expired cache data * * @access public * @return boolean True on success, false otherwise. */ function gc() { return eaccelerator_gc(); }
/** * Smarty Cache Handler<br> * utilizing eAccelerator extension (http://eaccelerator.net/HomeUk)<br> * * Name: smarty_cache_eaccelerator<br> * Type: Cache Handler<br> * Purpose: Replacement for the file based cache handling of Smarty. smarty_cache_eaccelerator() is * using Turck eaccelerator extension to minimize disk usage. * File: cache.eaccelerator.php<br> * Date: Dec 2, 2003<br> * * Usage Example<br> * <pre> * $smarty = new Smarty; * $smarty->cache_handler_func = 'smarty_cache_eaccelerator'; * $smarty->caching = true; * $smarty->display('index.tpl'); * </pre> * * @author André Rabold * @version RC-1 * * @param string $action Cache operation to perform ( read | write | clear ) * @param mixed $smarty Reference to an instance of Smarty * @param string $cache_content Reference to cached contents * @param string $tpl_file Template file name * @param string $cache_id Cache identifier * @param string $compile_id Compile identifier * @param integer $exp_time Expiration time * @return boolean TRUE on success, FALSE otherwise * * @link http://eaccelerator.net/HomeUk * (eaccelerator homepage) * @link http://smarty.php.net/manual/en/section.template.cache.handler.func.php * (Smarty online manual) */ function smarty_cache_eaccelerator($action, &$smarty, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null) { if(!function_exists("eaccelerator")) { $smarty->trigger_error("cache_handler: PHP Extension \"eaccelerator\" (http://eaccelerator.net/HomeUk) not installed."); return false; } // Create unique cache id: // We are using smarty's internal functions here to be as compatible as possible. $_auto_id = $smarty->_get_auto_id($cache_id, $compile_id); $_cache_file = substr($smarty->_get_auto_filename(".", $tpl_file, $_auto_id),2); $eaccelerator_id = "smarty_eaccelerator|".$_cache_file; // The index contains all stored cache ids in a hierarchy and can be iterated later $eaccelerator_index_id = "smarty_eaccelerator_index"; switch ($action) { case 'read': // read cache from shared memory $cache_content = eaccelerator_get($eaccelerator_id); if (!is_null($cache_content) && _eaccelerator_hasexpired($cache_content)) { // Cache has been expired so we clear it now by calling ourself with another parameter :) $cache_content = null; smarty_cache_eaccelerator('clear', $smarty, $cache_content, $tpl_file, $cache_id, $compile_id); } $return = true; break; case 'write': // save cache to shared memory $current_time = time(); if (is_null($exp_time) || $exp_time < $current_time) $ttl = 0; else $ttl = $exp_time - time(); // First run garbage collection eaccelerator_gc(); // Put content into cache eaccelerator_lock($eaccelerator_id); eaccelerator_put($eaccelerator_id, $cache_content, $ttl); // Create an index association eaccelerator_lock($eaccelerator_index_id); $eaccelerator_index = eaccelerator_get($eaccelerator_index_id); if (!is_array($eaccelerator_index)) $eaccelerator_index = array(); $indexes = explode(DIRECTORY_SEPARATOR, $_cache_file); $_pointer =& $eaccelerator_index; foreach ($indexes as $index) { if (!isset($_pointer[$index])) $_pointer[$index] = array(); $_pointer =& $_pointer[$index]; } $_pointer = $eaccelerator_id; eaccelerator_put($eaccelerator_index_id, $eaccelerator_index, 0); eaccelerator_unlock($eaccelerator_index_id); eaccelerator_unlock($eaccelerator_id); break; case 'clear': // clear cache info eaccelerator_lock($eaccelerator_index_id); $eaccelerator_index = eaccelerator_get($eaccelerator_index_id); if (is_array($eaccelerator_index)) { if (empty($cache_id) && empty($compile_id) && empty($tpl_file)) { // clear all cache eaccelerator_lock($eaccelerator_id); _eaccelerator_clear_cache($eaccelerator_index); eaccelerator_unlock($eaccelerator_id); $eaccelerator_index = array(); } else { // clear single file or cache group $indexes = explode(DIRECTORY_SEPARATOR, $_cache_file); if (is_null($tpl_file)) array_pop($indexes); $_pointer =& $eaccelerator_index; $_failed = false; foreach ($indexes as $index) { if (!isset($_pointer[$index])) { $_failed = true; break; } $_pointer =& $_pointer[$index]; } if (!$_failed) { if (is_array($_pointer)) { // Clear cache group _eaccelerator_clear_cache($_pointer); } else { // Clear single file eaccelerator_lock($_pointer); eaccelerator_rm($_pointer); eaccelerator_unlock($_pointer); } $_pointer = null; } } } eaccelerator_put($eaccelerator_index_id, $eaccelerator_index, 0); eaccelerator_unlock($eaccelerator_index_id); $return = true; break; default: // error, unknown action $smarty->trigger_error("cache_handler: unknown action \"$action\""); $return = false; break; } return $return; }
public function flush() { eaccelerator_gc(); eaccelerator_clear(); eaccelerator_removed_scripts(); }
public function gc($force) { if (rand(1, Cache::GC_DIVISOR) < Cache::GC_PROBABILITY || $force) { eaccelerator_gc(); } }
/** * Puts value in the cache under key for ttl seconds. * * - It may "miss" so shouldn't be depended on * - Uses the cache engine chosen in the ACP and saved in settings.php * - It supports: * Turck MMCache: http://turck-mmcache.sourceforge.net/index_old.html#api * Xcache: http://xcache.lighttpd.net/wiki/XcacheApi * memcache: http://www.php.net/memcache * APC: http://www.php.net/apc * eAccelerator: http://bart.eaccelerator.net/doc/phpdoc/ * Zend: http://files.zend.com/help/Zend-Platform/output_cache_functions.htm * Zend: http://files.zend.com/help/Zend-Platform/zend_cache_functions.htm * * @param string $key * @param string|int|mixed[]|null $value * @param int $ttl = 120 */ function cache_put_data($key, $value, $ttl = 120) { global $cache_memcached, $memcached, $cache_hits, $cache_count, $db_show_debug; 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' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(true); } $key = cache_get_key($key); $value = $value === null ? null : serialize($value); switch ($cache_accelerator) { case 'memcached': // The simple yet efficient memcached. if (function_exists('memcached_set') || function_exists('memcache_set') && !empty($cache_memcached)) { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return; } memcache_set($memcached, $key, $value, 0, $ttl); } break; case 'eaccelerator': // eAccelerator... if (function_exists('eaccelerator_put')) { if (mt_rand(0, 10) == 1) { eaccelerator_gc(); } if ($value === null) { @eaccelerator_rm($key); } else { eaccelerator_put($key, $value, $ttl); } } break; case 'mmcache': // Turck MMCache? if (function_exists('mmcache_put')) { if (mt_rand(0, 10) == 1) { mmcache_gc(); } if ($value === null) { @mmcache_rm($key); } else { mmcache_lock($key); mmcache_put($key, $value, $ttl); mmcache_unlock($key); } } break; case 'apc': case 'apcu': // Alternative PHP Cache, ahoy! if (function_exists('apc_store')) { // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'elkarte'); } else { apc_store($key . 'elkarte', $value, $ttl); } } break; case 'zend': // Zend Platform/ZPS/etc. if (function_exists('zend_shm_cache_store')) { zend_shm_cache_store('ELK::' . $key, $value, $ttl); } elseif (function_exists('output_cache_put')) { output_cache_put($key, $value); } break; case 'xcache': if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) { if ($value === null) { xcache_unset($key); } else { xcache_set($key, $value, $ttl); } } break; default: // Otherwise custom cache? if ($value === null) { @unlink(CACHEDIR . '/data_' . $key . '.php'); } else { $cache_data = '<' . '?' . 'php if (!defined(\'ELK\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}'; // Write out the cache file, check that the cache write was successful; all the data must be written // If it fails due to low diskspace, or other, remove the cache file if (@file_put_contents(CACHEDIR . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) { @unlink(CACHEDIR . '/data_' . $key . '.php'); } } break; } if (function_exists('call_integration_hook')) { call_integration_hook('cache_put_data', array($key, $value, $ttl)); } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = microtime(true) - $st; } }
/** * Removes all expired items from the cache store * * @return boolean true on success, false on failure **/ public function flushExpired() { $this->Logger->debug('Flush all expired called.'); eaccelerator_gc(); return true; }
/** * (non-PHPdoc) * @see Cache::clear() */ public function clear() { return eaccelerator_gc(); }
function cache_put_data($key, $value, $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' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . $key; $value = $value === null ? null : serialize($value); // The simple yet efficient memcached. if (function_exists('memcache_set') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return; } memcache_set($memcached, $key, $value, 0, $ttl); } elseif (function_exists('eaccelerator_put')) { if (mt_rand(0, 10) == 1) { eaccelerator_gc(); } if ($value === null) { @eaccelerator_rm($key); } else { eaccelerator_put($key, $value, $ttl); } } elseif (function_exists('mmcache_put')) { if (mt_rand(0, 10) == 1) { mmcache_gc(); } if ($value === null) { @mmcache_rm($key); } else { mmcache_put($key, $value, $ttl); } } elseif (function_exists('apc_store')) { // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'smf'); } else { apc_store($key . 'smf', $value, $ttl); } } elseif (function_exists('output_cache_put')) { output_cache_put($key, $value); } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); } }
/** * Perform cache garbage collection * * @return void */ function tidy() { eaccelerator_gc(); set_config('cache_last_gc', time(), true); }
/** * flush() * Flush the entire cache. * * @param none * @return mixed bool * Returns TRUE */ function flush() { parent::flush(); if ($this->lock()) { // Get lookup table to be able to keep track of bins $lookup = $this->getLookup(); // If the lookup table is empty, remove lock and return if (empty($lookup) || !is_array($lookup)) { $this->unlock(); return TRUE; } // Cycle through keys and remove each entry from the cache foreach ($lookup as $k => $expire) { if ($expire != CACHE_PERMANENT && $expire <= time()) { eaccelerator_rm($k); unset($lookup[$k]); } } // Resave the lookup table (even on failure) $lookup = $this->setLookup($lookup); // Remove lock $this->unlock(); eaccelerator_gc(); } return TRUE; }
function gc() { eaccelerator_gc(); }
function cache_put_data($key, $value, $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' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':', '-'); $value = $value === null ? null : serialize($value); // The simple yet efficient memcached. if (function_exists('memcache_set') && isset($modSettings['cache_memcached']) && trim($modSettings['cache_memcached']) != '') { // Not connected yet? if (empty($memcached)) { get_memcached_server(); } if (!$memcached) { return; } memcache_set($memcached, $key, $value, 0, $ttl); } elseif (function_exists('eaccelerator_put')) { if (mt_rand(0, 10) == 1) { eaccelerator_gc(); } if ($value === null) { @eaccelerator_rm($key); } else { eaccelerator_put($key, $value, $ttl); } } elseif (function_exists('mmcache_put')) { if (mt_rand(0, 10) == 1) { mmcache_gc(); } if ($value === null) { @mmcache_rm($key); } else { mmcache_put($key, $value, $ttl); } } elseif (function_exists('apc_store')) { // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'smf'); } else { apc_store($key . 'smf', $value, $ttl); } } elseif (function_exists('output_cache_put')) { output_cache_put($key, $value); } elseif (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) { if ($value === null) { xcache_unset($key); } else { xcache_set($key, $value, $ttl); } } elseif (function_exists('fwrite')) { if ($value === null) { @unlink($cachedir . '/data_' . $key . '.php'); } else { $fp = @fopen($cachedir . '/data_' . $key . '.php', 'w'); if ($fp) { // Write the header. @flock($fp, LOCK_EX); fwrite($fp, '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'); @flock($fp, LOCK_UN); fclose($fp); } } } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); } }
/** * Put data in the cache * * Adds data to whatever cache method we're using * * @param string $key the cache data identifier * @param mixed $value the value to be stored * @param int $ttl how long are we going to cache this data (in seconds) * @return void * @since 0.1.0 */ function smfapi_cachePutData($key, $value, $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' => 'put', 's' => $value === null ? 0 : strlen(serialize($value))); $st = microtime(); } $key = md5($boardurl . filemtime($sourcedir . '/Load.php')) . '-SMF-' . strtr($key, ':', '-'); $value = $value === null ? null : serialize($value); // eAccelerator... if (function_exists('eaccelerator_put')) { if (mt_rand(0, 10) == 1) { eaccelerator_gc(); } if ($value === null) { @eaccelerator_rm($key); } else { eaccelerator_put($key, $value, $ttl); } } elseif (function_exists('mmcache_put')) { if (mt_rand(0, 10) == 1) { mmcache_gc(); } if ($value === null) { @mmcache_rm($key); } else { mmcache_put($key, $value, $ttl); } } elseif (function_exists('apc_store')) { // An extended key is needed to counteract a bug in APC. if ($value === null) { apc_delete($key . 'smf'); } else { apc_store($key . 'smf', $value, $ttl); } } elseif (function_exists('output_cache_put')) { output_cache_put($key, $value); } elseif (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) { if ($value === null) { xcache_unset($key); } else { xcache_set($key, $value, $ttl); } } else { if ($value === null) { @unlink($cachedir . '/data_' . $key . '.php'); } else { $cache_data = '<' . '?' . 'php if (!defined(\'SMF\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}' . '?' . '>'; $fh = @fopen($cachedir . '/data_' . $key . '.php', 'w'); if ($fh) { // write the file. set_file_buffer($fh, 0); flock($fh, LOCK_EX); $cache_bytes = fwrite($fh, $cache_data); flock($fh, LOCK_UN); fclose($fh); // check that the cache write was successful; all the data should be written // if it fails due to low diskspace, remove the cache file if ($cache_bytes != strlen($cache_data)) { @unlink($cachedir . '/data_' . $key . '.php'); } } } } if (isset($db_show_debug) && $db_show_debug === true) { $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); } return; }
public function delete_expired() { eaccelerator_gc(); return TRUE; }
/** * Garbage collect stale sessions from the SessionHandler backend. * * @param integer $maxlifetime The maximum age of a session. * * @return boolean True on success, false otherwise. */ public function gc($maxlifetime = null) { eaccelerator_gc(); return true; }
function expire() { return eaccelerator_gc(); }