public function index($arguments) { $news = new news(ConnectionFactory::get('mongo')); $articles = new articles(ConnectionFactory::get('mongo')); $notices = new notices(ConnectionFactory::get('redis')); $irc = new irc(ConnectionFactory::get('redis')); $quotes = new quotes(ConnectionFactory::get('mongo')); $forums = new forums(ConnectionFactory::get('redis')); // Set all site-wide notices. foreach ($notices->getAll() as $notice) { Error::set($notice, true); } // Fetch the easy data. $this->view['news'] = $news->getNewPosts(); $this->view['shortNews'] = $news->getNewPosts(true); $this->view['newArticles'] = $articles->getNewPosts('new', 1, 5); $this->view['ircOnline'] = $irc->getOnline(); $this->view['randomQuote'] = $quotes->getRandom(); $this->view['fPosts'] = $forums->getNew(); // Get online users. $apc = new APCIterator('user', '/' . Cache::PREFIX . 'user_.*/'); $this->view['onlineUsers'] = array(); while ($apc->valid()) { $current = $apc->current(); array_push($this->view['onlineUsers'], substr($current['key'], strlen(Cache::PREFIX) + 5)); $apc->next(); } // Set title. Layout::set('title', 'Home'); }
/** * clear static cache with prefix, don't use except in clear-cache-watcher * * @internal */ public static function clear($cacheIdPrefix) { if (extension_loaded('apc')) { if (PHP_SAPI == 'cli') { Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic' => $cacheIdPrefix)); } else { if (!class_exists('APCIterator')) { throw new Kwf_Exception_NotYetImplemented("We don't want to clear the whole"); } else { static $prefix; if (!isset($prefix)) { $prefix = Kwf_Cache_Simple::getUniquePrefix() . '-'; } $it = new APCIterator('user', '#^' . preg_quote($prefix . $cacheIdPrefix) . '#', APC_ITER_NONE); if ($it->getTotalCount() && !$it->current()) { //APCIterator is borked, delete everything //see https://bugs.php.net/bug.php?id=59938 if (extension_loaded('apcu')) { apc_clear_cache(); } else { apc_clear_cache('user'); } } else { //APCIterator seems to work, use it for deletion apc_delete($it); } } } } else { //don't use $cacheIdPrefix as filenames are base64 encoded foreach (glob('cache/simple/*') as $f) { unlink($f); } } }
public static function ApcPurge($func, $id) { $apc = new APCIterator('user', '/' . Cache::PREFIX . 'data_' . get_called_class() . '_' . $func . '-' . $id . '.*/'); while ($apc->valid()) { $current = $apc->current(); apc_delete($current['key']); $apc->next(); } }
public function testWithTTL() { $backend = $this->getBackend(); $dep = new \Cachet\Dependency\TTL(300); $backend->set(new \Cachet\Item('cache', 'foo', 'bar', $dep)); $iter = new \APCIterator('user', "~^{$this->backendPrefix}cache/foo\$~"); $ttl = $iter->current()['ttl']; // surely not longer than 2 seconds! $this->assertTrue($ttl >= 298 && $ttl <= 300); }
/** * @param string $className * @depreciated */ public function clearClassCache($className = null) { $iterator = new \APCIterator('^user^'); while ($iterator->current()) { $tKey = $iterator->key(); if (mb_strpos($tKey, $className . '::') !== false) { apc_delete($tKey); } $iterator->next(); } }
/** * Get metadata of an item. * * @param string $normalizedKey * @return array|boolean Metadata on success, false on failure * @throws Exception\ExceptionInterface */ protected function internalGetMetadata(&$normalizedKey) { $options = $this->getOptions(); $prefix = $options->getNamespace() . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; // @see http://pecl.php.net/bugs/bug.php?id=22564 if (!apc_exists($internalKey)) { $metadata = false; } else { $format = \APC_ITER_ALL ^ \APC_ITER_VALUE ^ \APC_ITER_TYPE ^ \APC_ITER_REFCOUNT; $regexp = '/^' . preg_quote($internalKey, '/') . '$/'; $it = new BaseApcIterator('user', $regexp, $format, 100, \APC_LIST_ACTIVE); $metadata = $it->current(); } if (!$metadata) { return false; } $this->normalizeMetadata($metadata); return $metadata; }
<?php error_reporting(E_ALL & ~E_USER_NOTICE & ~E_NOTICE); echo "== No Search ==\n"; $it = new APCIterator('user'); apc_store('sample', 'x'); apc_store('another_sample', 'x'); foreach ($it as $key => $val) { // skip to end } var_dump($it->valid(), $it->key(), $it->current(), $it->next()); echo "== Search ==\n"; $it = new APCIterator('user', '/^b/'); // No elements, end? var_dump($it->valid(), $it->key(), $it->current(), $it->next());
public function current() { $data = parent::current(); return extension_loaded('apcu') && version_compare(phpversion('apcu'), '4.0.3') < 0 ? array('type' => 'user', 'key' => $data['key'], 'value' => $data['value'], 'num_hits' => $data['nhits'], 'mtime' => $data['mtime'], 'creation_time' => $data['ctime'], 'deletion_time' => $data['dtime'], 'access_time' => $data['atime'], 'ref_count' => $data['ref_count'], 'mem_size' => $data['mem_size'], 'ttl' => $data['ttl']) : $data; }
protected function del_old_cached() { $t = time(); $apc_user_info = apc_cache_info('user', true); if (!empty($apc_user_info['ttl'])) { $apc_ttl = $apc_user_info['ttl'] / 2; $check_period = $apc_ttl; } if (empty($check_period) || $check_period > 1800) { $check_period = 1800; } $ittl = new \APCIterator('user', '/^' . preg_quote($this->defragmentation_prefix) . '$/', APC_ITER_ATIME, 1); $cttl = $ittl->current(); $previous_cleaning = $cttl[self::apc_arr_atime]; if (empty($previous_cleaning) || $t - $previous_cleaning > $check_period) { apc_store($this->defragmentation_prefix, $t, $check_period); $this->del_old(); } return true; }