public function status() { $status = wincache_ucache_info(true); $return['缓存命中'] = $status['total_hit_count']; $return['缓存未命中'] = $status['total_miss_count']; return $return; }
/** * Fetch an array of all keys stored in cache * * @return array Returns the array of cache keys */ protected function _getCacheKeys() { $ci = wincache_ucache_info(); $keys = array(); foreach ($ci['ucache_entries'] as $entry) { $keys[] = $entry['key_name']; } return $keys; }
public function gc() { $allinfo = wincache_ucache_info(); $keys = $allinfo['cache_entries']; $secret = $this->_hash; foreach ($keys as $key) { if (strpos($key['key_name'], $secret . '-cache-')) { wincache_ucache_get($key['key_name']); } } }
function cs_cache_info() { $form = array(); $info = wincache_ucache_info(); foreach ($info['ucache_entries'] as $num => $data) { $handle = $data['key_name'] . ' (' . $num . ')'; $age = time() - $data['age_seconds']; $form[$handle] = array('name' => $handle, 'time' => $age, 'size' => $data['value_size']); } ksort($form); return array_values($form); }
/** * @return Array */ public function keys() { $info = wincache_ucache_info(); $list = $info['ucache_entries']; $keys = array(); if (is_null($list)) { return array(); } foreach ($list as $entry) { $keys[] = $entry['key_name']; } return $keys; }
/** * Delete all keys from the cache * * @param bool $check if true will check expiration, otherwise delete all * @return bool True if the cache was successfully cleared, false otherwise */ public function clear($check) { if ($check) { return true; } $info = wincache_ucache_info(); $cacheKeys = $info['ucache_entries']; unset($info); foreach ($cacheKeys as $key) { wincache_ucache_delete($key['key_name']); } return true; }
public function filter($prefix) { $prefixLen = strlen($prefix); $info = wincache_ucache_info(); $keysToDelete = array(); foreach ($info['ucache_entries'] as $entry) { if (empty($entry['is_session']) && 0 === strncmp($entry['key_name'], $prefix, $prefixLen)) { $keysToDelete[] = $entry['key_name']; } } if ($keysToDelete) { wincache_ucache_delete($keysToDelete); } return true; }
/** * Retrieve an external iterator * * Returns an external iterator. * * @param string|null $filter A PCRE regular expression. * Only matching keys will be iterated over. * Setting this to NULL matches all keys of this instance. * @param bool $keysOnly Whether to return only the keys, * or return both the keys and values. * * @return ArrayObject An array with all matching keys as array keys, * and values as array values. If $keysOnly is TRUE, the array keys are * numeric, and the array values are key names. */ public function getIterator($filter = null, $keysOnly = false) { $info = wincache_ucache_info(); $result = array(); foreach ($info['ucache_entries'] as $entry) { if (!$entry['is_session'] && 0 === strpos($entry['key_name'], $this->persistentId)) { $localKey = strstr($entry['key_name'], $this->persistentId); if (null === $filter || preg_match($filter, $localKey)) { if ($keysOnly) { $result[] = $localKey; } else { $result[$localKey] = apc_fetch($localKey); } } } } return new ArrayObject($result); }
function stats() { echo "<p>\n"; foreach ($this->stats as $stat => $n) { echo "<strong>{$stat}</strong> {$n}"; echo "<br/>\n"; } echo "</p>\n"; echo "<h3>WinCache:</h3>"; foreach ($this->group_ops as $group => $ops) { if (!isset($_GET['debug_queries']) && 500 < count($ops)) { $ops = array_slice($ops, 0, 500); echo "<big>Too many to show! <a href='" . add_query_arg('debug_queries', 'true') . "'>Show them anyway</a>.</big>\n"; } echo "<h4>{$group} commands</h4>"; echo "<pre>\n"; $lines = array(); foreach ($ops as $op) { $lines[] = $this->colorize_debug_line($op); } print_r($lines); echo "</pre>\n"; } if ($this->debug) { $wincache_info = wincache_ucache_info(); echo "<p>"; echo "<strong>Cache Hits:</strong> {$wincache_info['total_hit_count']}<br/>\n"; echo "<strong>Cache Misses:</strong> {$wincache_info['total_miss_count']}\n"; echo "</p>\n"; } }
/** * Get metadata of an item. * * @param string $normalizedKey * @return array|bool Metadata on success, false on failure * @throws Exception\ExceptionInterface */ protected function internalGetMetadata(&$normalizedKey) { $options = $this->getOptions(); $namespace = $options->getNamespace(); $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; $info = wincache_ucache_info(true, $internalKey); if (isset($info['ucache_entries'][1])) { $metadata = $info['ucache_entries'][1]; $this->normalizeMetadata($metadata); return $metadata; } return false; }
/** * Clear contents of cache backend * @return bool * @param $suffix string * @param $lifetime int **/ function reset($suffix = NULL, $lifetime = 0) { if (!$this->dsn) { return TRUE; } $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/'; $parts = explode('=', $this->dsn, 2); switch ($parts[0]) { case 'apc': case 'apcu': $info = apc_cache_info('user'); if (!empty($info['cache_list'])) { $key = array_key_exists('info', $info['cache_list'][0]) ? 'info' : 'key'; $mtkey = array_key_exists('mtime', $info['cache_list'][0]) ? 'mtime' : 'modification_time'; foreach ($info['cache_list'] as $item) { if (preg_match($regex, $item[$key]) && $item[$mtkey] + $lifetime < time()) { apc_delete($item[$key]); } } } return TRUE; case 'redis': $fw = Base::instance(); $keys = $this->ref->keys($this->prefix . '.*' . $suffix); foreach ($keys as $key) { $val = $fw->unserialize($this->ref->get($key)); if ($val[1] + $lifetime < time()) { $this->ref->del($key); } } return TRUE; case 'memcache': foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) { foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) { foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) { if (is_array($data)) { foreach ($data as $key => $val) { if (preg_match($regex, $key) && $val[1] + $lifetime < time()) { memcache_delete($this->ref, $key); } } } } } } return TRUE; case 'wincache': $info = wincache_ucache_info(); foreach ($info['ucache_entries'] as $item) { if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) { wincache_ucache_delete($item['key_name']); } } return TRUE; case 'xcache': return TRUE; /* Not supported */ /* Not supported */ case 'folder': if ($glob = @glob($parts[1] . '*')) { foreach ($glob as $file) { if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) { @unlink($file); } } } return TRUE; } return FALSE; }
/** * @return driverStatistic */ public function getStats() { $memInfo = wincache_ucache_meminfo(); $info = wincache_ucache_info(); $date = (new \DateTime())->setTimestamp(time() - $info['total_cache_uptime']); return (new driverStatistic())->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822)))->setSize($memInfo['memory_free'] - $memInfo['memory_total'])->setData(implode(', ', array_keys($this->itemInstances)))->setRawData($memInfo); }
/** * {@inheritdoc} * * @param string $prefix * @return array */ public function queryKeys($prefix = null) { $info = wincache_ucache_info(); $entries = array(); foreach ($info['ucache_entries'] as $entry) { if ($prefix === null) { $entries[] = $entry['key_name']; } else { if (substr($entry['key_name'], 0, strlen($prefix)) === $prefix) { $entries[] = $entry['key_name']; } } } return $entries; }
/** * Get Cache Metadata * * @param mixed key to get cache metadata on * @return mixed array on success/false on failure */ public function get_metadata($id) { if ($stored = wincache_ucache_info(FALSE, $id)) { $age = $stored['ucache_entries'][1]['age_seconds']; $ttl = $stored['ucache_entries'][1]['ttl_seconds']; $hitcount = $stored['ucache_entries'][1]['hitcount']; return array('expire' => $ttl - $age, 'hitcount' => $hitcount, 'age' => $age, 'ttl' => $ttl); } return FALSE; }
/** * Delete all keys from the cache. This will clear every * item in the cache matching the cache config prefix. * * @param bool $check If true, nothing will be cleared, as entries will * naturally expire in wincache.. * @return bool True Returns true. */ public function clear($check) { if ($check) { return true; } $info = wincache_ucache_info(); $cacheKeys = $info['ucache_entries']; unset($info); foreach ($cacheKeys as $key) { if (strpos($key['key_name'], $this->_config['prefix']) === 0) { wincache_ucache_delete($key['key_name']); } } return true; }
/** * @inheritdoc */ public function getMeta($id) { if ($stored = wincache_ucache_info(false, $id)) { $age = $stored['ucache_entries'][1]['age_seconds']; $ttl = $stored['ucache_entries'][1]['ttl_seconds']; $hitCount = $stored['ucache_entries'][1]['hitcount']; return ['expire' => $ttl - $age, 'hitcount' => $hitCount, 'age' => $age, 'ttl' => $ttl]; } return false; }
/** * Return an array of stored cache ids * * @return array array of stored cache ids (string) */ public function getIds() { $res = array(); $array = wincache_ucache_info(); $records = $array['ucache_entries']; foreach ($records as $record) { $res[] = $record['key_name']; } return $res; }
/** * Get all cached data * * @return array */ public function all() { $hash = $this->options['hash']; $allinfo = wincache_ucache_info(); $data = array(); foreach ($allinfo['cache_entries'] as $key) { $name = $key['key_name']; $namearr = explode('-', $name); if ($namearr !== false && $namearr[0] == $hash && $namearr[1] == 'cache') { $group = $namearr[2]; if (!isset($data[$group])) { $item = new Auditor($group); } else { $item = $data[$group]; } if (isset($key['value_size'])) { $item->tally($key['value_size'] / 1024); } else { // Dummy, WINCACHE version is too low. $item->tally(1); } $data[$group] = $item; } } return $data; }
function init_cache_info($cache_data = SUMMARY_DATA) { global $ocache_mem_info, $ocache_file_info, $ocache_summary_info, $fcache_mem_info, $fcache_file_info, $fcache_summary_info, $rpcache_mem_info, $rpcache_file_info, $ucache_mem_info, $ucache_info, $scache_mem_info, $scache_info, $user_cache_available, $session_cache_available; if ($cache_data == SUMMARY_DATA || $cache_data == OCACHE_DATA) { $ocache_mem_info = wincache_ocache_meminfo(); $ocache_file_info = wincache_ocache_fileinfo(); $ocache_summary_info = get_ocache_summary($ocache_file_info['file_entries']); } if ($cache_data == SUMMARY_DATA || $cache_data == FCACHE_DATA) { $fcache_mem_info = wincache_fcache_meminfo(); $fcache_file_info = wincache_fcache_fileinfo(); $fcache_summary_info = get_fcache_summary($fcache_file_info['file_entries']); } if ($cache_data == SUMMARY_DATA || $cache_data == RCACHE_DATA) { $rpcache_mem_info = wincache_rplist_meminfo(); $rpcache_file_info = wincache_rplist_fileinfo(); } if ($user_cache_available && ($cache_data == SUMMARY_DATA || $cache_data == UCACHE_DATA)) { $ucache_mem_info = wincache_ucache_meminfo(); $ucache_info = wincache_ucache_info(); } if ($session_cache_available && ($cache_data == SUMMARY_DATA || $cache_data == SCACHE_DATA)) { $scache_mem_info = wincache_scache_meminfo(); $scache_info = wincache_scache_info(); } }
/** * {@inheritDoc} */ public function getStats() { $info = wincache_ucache_info(true); $meminfo = wincache_ucache_meminfo(); return array(CacheInterface::STATS_SIZE => $info['total_item_count'], CacheInterface::STATS_HITS => $info['total_hit_count'], CacheInterface::STATS_MISSES => $info['total_miss_count'], CacheInterface::STATS_UPTIME => $info['total_cache_uptime'], CacheInterface::STATS_MEMORY_USAGE => $meminfo['memory_total'], CacheInterface::STATS_MEMORY_AVAILIABLE => $meminfo['memory_free']); }
/** * @override \local_telemetry\request_state */ public function get_records() { $record = new stdClass(); $filecachefileinfo = wincache_fcache_fileinfo(true); if ($filecachefileinfo) { $record->f_f_uptime = $filecachefileinfo['total_cache_uptime']; $record->f_f_items = $filecachefileinfo['total_file_count']; $record->f_f_hits = $filecachefileinfo['total_hit_count']; $record->f_f_misses = $filecachefileinfo['total_miss_count']; } $filecachememinfo = wincache_fcache_meminfo(); if ($filecachememinfo) { $record->f_m_total = $filecachememinfo['memory_total']; $record->f_m_free = $filecachememinfo['memory_free']; $record->f_m_used_blocks = $filecachememinfo['num_used_blks']; $record->f_m_free_blocks = $filecachememinfo['num_free_blks']; $record->f_m_overhead = $filecachememinfo['memory_overhead']; } $opcodecachefileinfo = wincache_ocache_fileinfo(true); if ($opcodecachefileinfo) { $record->o_f_uptime = $opcodecachefileinfo['total_cache_uptime']; $record->o_f_items = $opcodecachefileinfo['total_file_count']; $record->o_f_hits = $opcodecachefileinfo['total_hit_count']; $record->o_f_misses = $opcodecachefileinfo['total_miss_count']; $record->o_f_islocal = $opcodecachefileinfo['is_local_cache']; } $opcodecachememinfo = wincache_ocache_meminfo(); if ($opcodecachememinfo) { $record->o_m_total = $opcodecachememinfo['memory_total']; $record->o_m_free = $opcodecachememinfo['memory_free']; $record->o_m_used_blocks = $opcodecachememinfo['num_used_blks']; $record->o_m_free_blocks = $opcodecachememinfo['num_free_blks']; $record->o_m_overhead = $opcodecachememinfo['memory_overhead']; } $resolvedpathcachefileinfo = wincache_rplist_fileinfo(true); if ($resolvedpathcachefileinfo) { $record->rp_f_files = $resolvedpathcachefileinfo['total_file_count']; } $resolvedpathcachememinfo = wincache_rplist_meminfo(); if ($resolvedpathcachememinfo) { $record->rp_m_total = $resolvedpathcachememinfo['memory_total']; $record->rp_m_free = $resolvedpathcachememinfo['memory_free']; $record->rp_m_used_blocks = $resolvedpathcachememinfo['num_used_blks']; $record->rp_m_free_blocks = $resolvedpathcachememinfo['num_free_blks']; $record->rp_m_overhead = $resolvedpathcachememinfo['memory_overhead']; } $sessioncacheinfo = wincache_scache_info(true); if ($sessioncacheinfo) { $record->s_i_uptime = $sessioncacheinfo['total_cache_uptime']; $record->s_i_items = $sessioncacheinfo['total_item_count']; $record->s_i_islocal = $sessioncacheinfo['is_local_cache']; $record->s_i_hits = $sessioncacheinfo['total_hit_count']; $record->s_i_misses = $sessioncacheinfo['total_miss_count']; } $sessioncachememinfo = wincache_scache_meminfo(); if ($sessioncachememinfo) { $record->s_m_total = $sessioncachememinfo['memory_total']; $record->s_m_free = $sessioncachememinfo['memory_free']; $record->s_m_used_blocks = $sessioncachememinfo['num_used_blks']; $record->s_m_free_blocks = $sessioncachememinfo['num_free_blks']; $record->s_m_overhead = $sessioncachememinfo['memory_overhead']; } $usercacheinfo = wincache_ucache_info(true); if ($usercacheinfo) { $record->u_i_uptime = $usercacheinfo['total_cache_uptime']; $record->u_i_items = $usercacheinfo['total_item_count']; $record->u_i_islocal = $usercacheinfo['is_local_cache']; $record->u_i_hits = $usercacheinfo['total_hit_count']; $record->u_i_misses = $usercacheinfo['total_miss_count']; } $usercachememinfo = wincache_ucache_meminfo(); if ($usercachememinfo) { $record->u_m_total = $usercachememinfo['memory_total']; $record->u_m_free = $usercachememinfo['memory_free']; $record->u_m_used_blocks = $usercachememinfo['num_used_blks']; $record->u_m_free_blocks = $usercachememinfo['num_free_blks']; $record->u_m_overhead = $usercachememinfo['memory_overhead']; } return array($record); }
/** * Get all metadata for an item * * @param array $keys * @param array $options * @return array * @throws Exception\ItemNotFoundException * * @triggers getMetadatas.pre(PreEvent) * @triggers getMetadatas.post(PostEvent) * @triggers getMetadatas.exception(ExceptionEvent) */ public function getMetadatas(array $keys, array $options = array()) { $baseOptions = $this->getOptions(); if (!$baseOptions->getReadable()) { return array(); } $this->normalizeOptions($options); $args = new ArrayObject(array('keys' => &$keys, 'options' => &$options)); try { $eventRs = $this->triggerPre(__FUNCTION__, $args); if ($eventRs->stopped()) { return $eventRs->last(); } $result = array(); foreach ($keys as $key) { $internalKey = $options['namespace'] . $baseOptions->getNamespaceSeparator() . $key; $info = wincache_ucache_info(true, $internalKey); $metadata = $info['ucache_entries'][1]; if (empty($metadata)) { if (!$options['ignore_missing_items']) { throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found"); } } else { $this->normalizeMetadata($metadata); $prefixL = strlen($options['namespace'] . $baseOptions->getNamespaceSeparator()); $result[substr($internalKey, $prefixL)] =& $metadata; } } if (!$options['ignore_missing_items']) { if (count($keys) != count($result)) { $missing = implode("', '", array_diff($keys, array_keys($result))); throw new Exception\ItemNotFoundException('Keys not found: ' . $missing); } } return $this->triggerPost(__FUNCTION__, $args, $result); } catch (\Exception $e) { return $this->triggerException(__FUNCTION__, $args, $e); } }
public function getMetaData($key) { if (!function_exists('wincache_ucache_info')) { return getMessage('Cache', 'unsupported', 'Wincache'); } if ($stored = wincache_ucache_info(false, $key)) { $age = $stored['ucache_entries'][1]['age_seconds']; $ttl = $stored['ucache_entries'][1]['ttl_seconds']; $hitcount = $stored['ucache_entries'][1]['hitcount']; return array('expire' => $ttl - $age, 'hitcount' => $hitcount, 'age' => $age, 'ttl' => $ttl); } return false; }
/** * Remove an item from the cache. * * @param string $key * @return bool */ public function forget($key) { if ($key == '*') { $this->flush(); return true; } $pattern = str_replace(['\\*', '*'], '.+', preg_quote($this->getPrefixWithLocale(true) . $key)); $check = false; $all = wincache_ucache_info(); if (isset($all['ucache_entries']) && $all['ucache_entries']) { foreach ($all['ucache_entries'] as $cache) { if (preg_match('~^' . $pattern . '$~i', $cache['key_name'])) { if (!wincache_ucache_delete($cache['key_name'])) { $check = false; } } } } return $check; }
/** * Clear contents of cache backend * @return bool * @param $suffix string * @param $lifetime int **/ function reset($suffix = NULL, $lifetime = 0) { if (!$this->dsn) { return TRUE; } $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/'; $parts = explode('=', $this->dsn, 2); switch ($parts[0]) { case 'apc': $info = apc_cache_info('user'); foreach ($info['cache_list'] as $item) { if (preg_match($regex, $item['info']) && $item['mtime'] + $lifetime < time()) { apc_delete($item['info']); } } return TRUE; case 'memcache': foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) { foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) { foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) { if (is_array($data)) { foreach ($data as $key => $val) { if (preg_match($regex, $key) && $val[1] + $lifetime < time()) { memcache_delete($this->ref, $key); } } } } } } return TRUE; case 'wincache': $info = wincache_ucache_info(); foreach ($info['ucache_entries'] as $item) { if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) { apc_delete($item['key_name']); } } return TRUE; case 'xcache': return TRUE; /* Not supported */ /* Not supported */ case 'folder': if ($glob = @glob($parts[1] . '*')) { foreach ($glob as $file) { if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) { @unlink($file); } } } return TRUE; } return FALSE; }
/** * Return an array of stored cache ids * * @return array array of stored cache ids (string) */ public function getIds() { $res = array(); $info = wincache_ucache_info(); if ($info['total_item_count'] <= 0) { return array(); } foreach ($info['ucache_entries'] as $record) { $res[] = $record['key_name']; } return $res; }
/** * @see wincache_ucache_info(); */ public function info($summary_only = false, $key = null) { if (is_string($key)) { return wincache_ucache_info($summary_only, $key); } return wincache_ucache_info($summary_only); }
/** * Get metadata of an item. * * Options: * - namespace <string> optional * - The namespace to use (Default: namespace of object) * - ignore_missing_items <boolean> optional * - Throw exception on missing item or return false * * @param string $normalizedKey * @param array $normalizedOptions * @return array|boolean Metadata or false on failure * @throws Exception * * @triggers getMetadata.pre(PreEvent) * @triggers getMetadata.post(PostEvent) * @triggers getMetadata.exception(ExceptionEvent) */ protected function internalGetMetadata(&$normalizedKey, array &$normalizedOptions) { $internalKey = $normalizedOptions['namespace'] . $this->getOptions()->getNamespaceSeparator() . $normalizedKey; $info = wincache_ucache_info(true, $internalKey); if (isset($info['ucache_entries'][1])) { $metadata = $info['ucache_entries'][1]; } if (!$metadata) { if (!$normalizedOptions['ignore_missing_items']) { throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found"); } return false; } $this->normalizeMetadata($metadata); return $metadata; }
/** * {@inheritdoc} */ protected function doGetStats() { $info = wincache_ucache_info(); $meminfo = wincache_ucache_meminfo(); return array(Cache::STATS_HITS => $info['total_hit_count'], Cache::STATS_MISSES => $info['total_miss_count'], Cache::STATS_UPTIME => $info['total_cache_uptime'], Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'], Cache::STATS_MEMORY_AVAILIABLE => $meminfo['memory_free']); }
/** * {@inheritdoc} * * @param string $prefix * @return array */ public function queryKeys($prefix = null) { $info = wincache_ucache_info(); $entries = array(); if (!$prefix) { $prefix = $this->_prefix; } else { $prefix = $this->getPrefixedIdentifier($prefix); } foreach ($info['ucache_entries'] as $entry) { $keys[] = !empty($prefix) ? str_replace($prefix, '', $entry['key_name']) : $entry['key_name']; } return $entries; }