private function hasMatchFor($id, $key, DIWikiPage $subject) { $key = $id . '#' . $key; if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $requestOptions = new RequestOptions(); $requestOptions->limit = 1; $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions); $this->cache->save($key, $result !== array()); return $result !== array(); }
private function saveToCache($key, $list, $time, $ttl) { $this->timestamp = $time; $this->isCached = false; $data = array('time' => $this->timestamp, 'list' => serialize($list)); $this->cache->save($key, $data, $ttl); }
/** * Cached content is serialized in an associative array following: * { 'revId' => $revisionId, 'text' => (...) } */ private function saveToCache($key, array $content) { $this->timestamp = wfTimestamp(TS_UNIX); $this->isCached = false; $data = array('time' => $this->timestamp, 'content' => serialize($content)); $this->cache->save($key, $data, $this->cacheOptions->ttl); }
private function saveToCache($key, $optionsKey, $list, $time, $ttl) { $this->timestamp = $time; $this->isCached = false; $data = unserialize($this->cache->fetch($key)); $data[$optionsKey] = array('time' => $this->timestamp, 'list' => $list); $this->cache->save($key, serialize($data), $ttl); }
protected function doReadJsonContentsFromFileBy($languageCode, $cacheKey) { $contents = json_decode(file_get_contents($this->getFileForLanguageCode($languageCode)), true); if ($contents !== null && json_last_error() === JSON_ERROR_NONE) { $this->cache->save($cacheKey, $contents, $this->ttl); return $contents; } throw new RuntimeException(ErrorCode::getMessageFromJsonErrorCode(json_last_error())); }
/** * @since 2.5 * * @param CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator * * @return null|string */ public function createSlotFrom(CompositePropertyTableDiffIterator $compositePropertyTableDiffIterator) { $orderedDiffByTable = $compositePropertyTableDiffIterator->getOrderedDiffByTable(); if ($orderedDiffByTable === array()) { return null; } $slot = $this->getSlot($compositePropertyTableDiffIterator); $this->cache->save($slot, $orderedDiffByTable); return $slot; }
private function saveToCache($key, $optionsKey, $list, $time, $ttl) { $this->timestamp = $time; $this->isFromCache = false; // Collect the options keys $data = unserialize($this->cache->fetch($key)); $data[$optionsKey] = true; $this->cache->save($key, serialize($data), $ttl); $data = array('time' => $this->timestamp, 'list' => $list); $this->cache->save($optionsKey, serialize($data), $ttl); }
private function findMatchesWith($id, $key, DIWikiPage $subject, $requestOptions) { $key = $id . '#' . $key . '#' . $requestOptions->getHash(); if ($this->cache->contains($key)) { return $this->cache->fetch($key); } $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions); $this->cache->save($key, $result); wfDebugLog('smw', __METHOD__ . " {$id} and " . $subject->getDBKey() . "\n"); return $result; }
private function findMatchesFor($id, $key, DIWikiPage $subject) { $key = 'f#' . $id . '#' . $key; if ($this->cache->contains($key)) { return unserialize($this->cache->fetch($key)); } $requestOptions = new RequestOptions(); $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions); $this->cache->save($key, serialize($result)); wfDebugLog('smw', __METHOD__ . " {$id} and " . $subject->getDBKey() . "\n"); return $result; }
/** * @since 2.4 * * @param DIProperty $property * * @return integer|false */ public function getAllowedValuesBy(DIProperty $property) { $allowsValues = array(); $key = 'al:' . $property->getKey(); // Guard against high frequency lookup if ($this->intermediaryMemoryCache->contains($key)) { return $this->intermediaryMemoryCache->fetch($key); } $dataItems = $this->cachedPropertyValuesPrefetcher->getPropertyValues($property->getCanonicalDiWikiPage(), new DIProperty('_PVAL')); if (is_array($dataItems) && $dataItems !== array()) { $allowsValues = $dataItems; } $this->intermediaryMemoryCache->save($key, $allowsValues); return $allowsValues; }
/** * @since 1.0 * * @return mixed */ public function execute() { list($key, $expiry) = $this->getKeysFromOptions(); $this->isFromCache = false; if ($this->cache->contains($key)) { $this->isFromCache = true; return $this->cache->fetch($key); } $response = parent::execute(); // Do not cache any failed response if ($this->getLastErrorCode() !== 0) { return $response; } $this->cache->save($key, $response, $expiry); return $response; }
private function loadListFromCache($location, $languages) { $id = self::CACHE . md5(json_encode($languages) . $this->ttl . self::VERSION); if ($this->cache->contains($id)) { return self::$internalLookupCache = $this->cache->fetch($id); } self::$internalLookupCache = array(); foreach ($languages as $languageCode) { // We silently ignore any error on purpose $contents = json_decode(@file_get_contents($location . $languageCode . '.json'), true); if ($contents === null || json_last_error() !== JSON_ERROR_NONE || !isset($contents[$languageCode])) { continue; } self::$internalLookupCache += array_fill_keys($contents[$languageCode], true); } $this->cache->save($id, self::$internalLookupCache); }
/** * Create an ExpElement for some internal resource, given by an * DIWikiPage object. This is the one place in the code where URIs * of wiki pages and user-defined properties are determined. A modifier * can be given to make variants of a URI, typically done for * auxiliary properties. In this case, the URI is modiied by appending * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not * occuring in MW titles). * * @param DIWikiPage $diWikiPage * @param boolean $markForAuxiliaryUsage * * @return ExpResource */ public function mapWikiPageToResourceElement(DIWikiPage $diWikiPage, $markForAuxiliaryUsage = false) { $modifier = $markForAuxiliaryUsage ? self::AUX_MARKER : ''; $hash = $this->cachePrefix . $diWikiPage->getHash() . $modifier; // If a persistent cache is injected use the ExpElement serializer because // not all cache layers support object de/serialization // ExpElement::newFromSerialization if ($this->cache->contains($hash)) { return $this->cache->fetch($hash); } if ($diWikiPage->getSubobjectName() !== '') { $modifier = $diWikiPage->getSubobjectName(); } $importDataItem = $this->tryToFindImportDataItem($diWikiPage, $modifier); if ($importDataItem instanceof DataItem) { list($localName, $namespace, $namespaceId) = $this->defineElementsForImportDataItem($importDataItem); } else { list($localName, $namespace, $namespaceId) = $this->defineElementsForDiWikiPage($diWikiPage, $modifier); } $resource = new ExpNsResource($localName, $namespace, $namespaceId, $diWikiPage); $this->cache->save($hash, $resource); return $resource; }
/** * @since 1.0 * * @param Container $container */ public function save(Container $container) { $this->internalCache->save($container->getId(), $container->getData(), $container->getExpiry()); $this->cache->save($container->getId(), serialize($container->getData()), $container->getExpiry()); unset($container); }
/** * @since 2.1 * * @param integer $id * @param string $title * @param integer $namespace */ public function addRedirectForId($id, $title, $namespace) { $this->insert($id, $title, $namespace); $hash = HashBuilder::createHashIdFromSegments($title, $namespace); $this->cache->save($hash, $id); }
/** * @since 2.1 * * @param string $id * @param string $hash */ public function saveToCache($id, $hash) { $this->cache->save($id, $hash); }