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();
 }
 /**
  * @since 2.1
  *
  * @param integer $id
  *
  * @return DIWikiPage|null
  */
 public function getDataItemForId($id)
 {
     if (!$this->cache->contains($id)) {
         $row = $this->connection->selectRow($this->tableName, array('smw_title', 'smw_namespace', 'smw_iw', 'smw_subobject'), array('smw_id' => $id), __METHOD__);
         if ($row === false) {
             return null;
         }
         $hash = HashBuilder::createHashIdFromSegments($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject);
         $this->saveToCache($id, $hash);
     }
     return HashBuilder::newDiWikiPageFromHash($this->cache->fetch($id));
 }
Exemple #3
0
 /**
  * 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, $list, $time, $ttl)
 {
     $this->timestamp = $time;
     $this->isCached = false;
     $data = array('time' => $this->timestamp, 'list' => serialize($list));
     $this->cache->save($key, $data, $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()));
 }
Exemple #7
0
 /**
  * @since 1.0
  *
  * @param string $id
  */
 public function delete($id)
 {
     $container = $this->read($id);
     foreach ($container->getLinkedList() as $linkedId) {
         $key = $this->getKey((string) $linkedId);
         $this->cache->delete($key);
         $this->internalCache->delete($key);
     }
     $this->cache->delete($this->getKey($id));
     $this->internalCache->delete($this->getKey($id));
 }
 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;
 }
Exemple #13
0
 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);
 }
 /**
  * @since 2.5
  *
  * @param string $slot
  * @param string|null $tableName
  *
  * @return TableChange[]
  */
 public function newTableChangeOpsFrom($slot, $tableName = null)
 {
     $start = microtime(true);
     $diffByTable = $this->cache->fetch($slot);
     $tableChangeOps = array();
     if ($diffByTable === false || $diffByTable === null) {
         $this->log(__METHOD__ . ' unknown slot :: ' . $slot);
         return array();
     }
     foreach ($diffByTable as $tblName => $diff) {
         if ($tableName !== null && $tableName !== $tblName) {
             continue;
         }
         $tableChangeOps[] = new TableChangeOp($tblName, $diff);
     }
     $this->log(__METHOD__ . ' procTime (sec): ' . round(microtime(true) - $start, 5));
     return $tableChangeOps;
 }
 /**
  * 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 2.1
  *
  * @param string $title
  * @param integer $namespace
  */
 public function deleteRedirectEntry($title, $namespace)
 {
     $this->delete($title, $namespace);
     $hash = HashBuilder::createHashIdFromSegments($title, $namespace);
     $this->cache->delete($hash);
 }
Exemple #17
0
 /**
  * @since 1.0
  *
  * @param string $id
  */
 public function delete($id)
 {
     $this->cache->delete($this->getKey($id));
     $this->internalCache->delete($this->getKey($id));
 }