public function delete($key, $flags = 0) { unset($this->bag[$key]); if (!($flags & self::WRITE_CACHE_ONLY)) { $this->backend->delete($key); } return true; }
/** * @see JobQueueAggregator::doAllGetReadyWikiQueues() */ protected function doGetAllReadyWikiQueues() { $key = $this->getReadyQueueCacheKey(); // If the cache entry wasn't present, is stale, or in .1% of cases otherwise, // regenerate the cache. Use any available stale cache if another process is // currently regenerating the pending DB information. $pendingDbInfo = $this->cache->get($key); if (!is_array($pendingDbInfo) || time() - $pendingDbInfo['timestamp'] > $this->cacheTTL || mt_rand(0, 999) == 0) { if ($this->cache->add("{$key}:rebuild", 1, 1800)) { // lock $pendingDbInfo = array('pendingDBs' => $this->findPendingWikiQueues(), 'timestamp' => time()); for ($attempts = 1; $attempts <= 25; ++$attempts) { if ($this->cache->add("{$key}:lock", 1, 60)) { // lock $this->cache->set($key, $pendingDbInfo); $this->cache->delete("{$key}:lock"); // unlock break; } } $this->cache->delete("{$key}:rebuild"); // unlock } } return is_array($pendingDbInfo) ? $pendingDbInfo['pendingDBs'] : array(); // cache is both empty and locked }
/** * Close the connection to the Swift proxy * * @return void */ protected function closeConnection() { if ($this->conn) { $this->srvCache->delete($this->getCredsCacheKey($this->auth->username)); $this->conn->close(); // close active cURL handles in CF_Http object $this->conn = null; $this->connStarted = 0; } }
protected function doFlushCaches() { static $types = array('empty', 'size', 'acquiredcount', 'delayedcount', 'abandonedcount'); foreach ($types as $type) { $this->cache->delete($this->getCacheKey($type)); } foreach ($this->partitionQueues as $queue) { $queue->doFlushCaches(); } }
/** * Log an unexpected exception for this backend. * This also sets the Status object to have a fatal error. * * @param Status|null $status * @param string $func * @param array $params * @param string $err Error string * @param int $code HTTP status * @param string $desc HTTP status description */ public function onError($status, $func, array $params, $err = '', $code = 0, $desc = '') { if ($status instanceof Status) { $status->fatal('backend-fail-internal', $this->name); } if ($code == 401) { // possibly a stale token $this->srvCache->delete($this->getCredsCacheKey($this->swiftUser)); } wfDebugLog('SwiftBackend', "HTTP {$code} ({$desc}) in '{$func}' (given '" . FormatJson::encode($params) . "')" . ($err ? ": {$err}" : "")); }
/** * @covers BagOStuff::getMulti */ public function testGetMulti() { $value1 = array('this' => 'is', 'a' => 'test'); $value2 = array('this' => 'is', 'another' => 'test'); $key1 = wfMemcKey('test1'); $key2 = wfMemcKey('test2'); $this->cache->add($key1, $value1); $this->cache->add($key2, $value2); $this->assertEquals($this->cache->getMulti(array($key1, $key2)), array($key1 => $value1, $key2 => $value2)); // cleanup $this->cache->delete($key1); $this->cache->delete($key2); }
/** * @covers BagOStuff::getMulti */ public function testGetMulti() { $value1 = array('this' => 'is', 'a' => 'test'); $value2 = array('this' => 'is', 'another' => 'test'); $value3 = array('testing a key that may be encoded when sent to cache backend'); $key1 = wfMemcKey('test1'); $key2 = wfMemcKey('test2'); $key3 = wfMemcKey('will-%-encode'); // internally, MemcachedBagOStuffs will encode to will-%25-encode $this->cache->add($key1, $value1); $this->cache->add($key2, $value2); $this->cache->add($key3, $value3); $this->assertEquals(array($key1 => $value1, $key2 => $value2, $key3 => $value3), $this->cache->getMulti(array($key1, $key2, $key3))); // cleanup $this->cache->delete($key1); $this->cache->delete($key2); $this->cache->delete($key3); }
/** * Log an unexpected exception for this backend. * This also sets the Status object to have a fatal error. * * @param $e Exception * @param $status Status|null * @param $func string * @param array $params * @return void */ protected function handleException(Exception $e, $status, $func, array $params) { if ($status instanceof Status) { if ($e instanceof AuthenticationException) { $status->fatal('backend-fail-connect', $this->name); } else { $status->fatal('backend-fail-internal', $this->name); } } if ($e->getMessage()) { trigger_error("{$func}: " . $e->getMessage(), E_USER_WARNING); } if ($e instanceof InvalidResponseException) { // possibly a stale token $this->srvCache->delete($this->getCredsCacheKey($this->auth->username)); $this->closeConnection(); // force a re-connect and re-auth next time } wfDebugLog('SwiftBackend', get_class($e) . " in '{$func}' (given '" . FormatJson::encode($params) . "')" . ($e->getMessage() ? ": {$e->getMessage()}" : "")); }
/** * @covers BagOStuff::getMulti */ public function testGetMulti() { $value1 = ['this' => 'is', 'a' => 'test']; $value2 = ['this' => 'is', 'another' => 'test']; $value3 = ['testing a key that may be encoded when sent to cache backend']; $value4 = ['another test where chars in key will be encoded']; $key1 = wfMemcKey('test1'); $key2 = wfMemcKey('test2'); // internally, MemcachedBagOStuffs will encode to will-%25-encode $key3 = wfMemcKey('will-%-encode'); $key4 = wfMemcKey('flowdb:flow_ref:wiki:by-source:v3:Parser\'s_"broken"_+_(page)_&_grill:testwiki:1:4.7'); $this->cache->add($key1, $value1); $this->cache->add($key2, $value2); $this->cache->add($key3, $value3); $this->cache->add($key4, $value4); $this->assertEquals([$key1 => $value1, $key2 => $value2, $key3 => $value3, $key4 => $value4], $this->cache->getMulti([$key1, $key2, $key3, $key4])); // cleanup $this->cache->delete($key1); $this->cache->delete($key2); $this->cache->delete($key3); $this->cache->delete($key4); }
/** * Purges the internal and external cache of the site list, forcing the list * of sites to be reloaded. * * @since 1.25 */ public function reset() { // purge cache $this->cache->delete($this->getCacheKey()); $this->sites = null; }
/** * @return void */ protected function doFlushCaches() { foreach (array('empty', 'size', 'acquiredcount') as $type) { $this->cache->delete($this->getCacheKey($type)); } }
public function delete($key) { return $this->writeStore->delete($key); }
public function clearCaches() { $key = $this->getLagTimeCacheKey(); $this->srvCache->delete($key); $this->mainCache->delete($key); }
/** * @see JobQueueAggregator::doPurge() */ protected function doPurge() { return $this->cache->delete($this->getReadyQueueCacheKey()); }
/** * @param WikiPage $page * @since 1.28 */ public function deleteOptionsKey($page) { $this->mMemc->delete($this->getOptionsKey($page)); }
/** * Get a message from the MediaWiki namespace, with caching. The key must * first be converted to two-part lang/msg form if necessary. * * Unlike self::get(), this function doesn't resolve fallback chains, and * some callers require this behavior. LanguageConverter::parseCachedTable() * and self::get() are some examples in core. * * @param string $title Message cache key with initial uppercase letter. * @param string $code Code denoting the language to try. * @return string|bool The message, or false if it does not exist or on error */ function getMsgFromNamespace($title, $code) { $this->load($code); if (isset($this->mCache[$code][$title])) { $entry = $this->mCache[$code][$title]; if (substr($entry, 0, 1) === ' ') { // The message exists, so make sure a string // is returned. return (string) substr($entry, 1); } elseif ($entry === '!NONEXISTENT') { return false; } elseif ($entry === '!TOO BIG') { // Fall through and try invididual message cache below } } else { // XXX: This is not cached in process cache, should it? $message = false; Hooks::run('MessagesPreLoad', array($title, &$message)); if ($message !== false) { return $message; } return false; } # Try the individual message cache $titleKey = wfMemcKey('messages', 'individual', $title); $entry = $this->mMemc->get($titleKey); if ($entry) { if (substr($entry, 0, 1) === ' ') { $this->mCache[$code][$title] = $entry; // The message exists, so make sure a string // is returned. return (string) substr($entry, 1); } elseif ($entry === '!NONEXISTENT') { $this->mCache[$code][$title] = '!NONEXISTENT'; return false; } else { # Corrupt/obsolete entry, delete it $this->mMemc->delete($titleKey); } } # Try loading it from the database $revision = Revision::newFromTitle(Title::makeTitle(NS_MEDIAWIKI, $title), false, Revision::READ_LATEST); if ($revision) { $content = $revision->getContent(); if (!$content) { // A possibly temporary loading failure. wfDebugLog('MessageCache', __METHOD__ . ": failed to load message page text for {$title} ({$code})"); $message = null; // no negative caching } else { // XXX: Is this the right way to turn a Content object into a message? // NOTE: $content is typically either WikitextContent, JavaScriptContent or // CssContent. MessageContent is *not* used for storing messages, it's // only used for wrapping them when needed. $message = $content->getWikitextForTransclusion(); if ($message === false || $message === null) { wfDebugLog('MessageCache', __METHOD__ . ": message content doesn't provide wikitext " . "(content model: " . $content->getContentHandler() . ")"); $message = false; // negative caching } else { $this->mCache[$code][$title] = ' ' . $message; $this->mMemc->set($titleKey, ' ' . $message, $this->mExpiry); } } } else { $message = false; // negative caching } if ($message === false) { // negative caching $this->mCache[$code][$title] = '!NONEXISTENT'; $this->mMemc->set($titleKey, '!NONEXISTENT', $this->mExpiry); } return $message; }