/**
  * @since 2.4
  *
  * @param DIWikiPage $subject
  * @param DIProperty $property
  * @param RequestOptions|null $requestOptions
  *
  * @return array
  */
 public function getPropertyValues(DIWikiPage $subject, DIProperty $property, RequestOptions $requestOptions = null)
 {
     $key = $property->getKey() . ':' . $subject->getSubobjectName() . ':' . ($requestOptions !== null ? $requestOptions->getHash() : null);
     $container = $this->blobStore->read($this->getRootHashFrom($subject));
     if ($container->has($key)) {
         return $container->get($key);
     }
     $dataItems = $this->store->getPropertyValues($subject, $property, $requestOptions);
     $container->set($key, $dataItems);
     $this->blobStore->save($container);
     return $dataItems;
 }
 public function testExpiry()
 {
     $blobStore = new BlobStore('Foo', $this->cache);
     $blobStore->setExpiryInSeconds(4);
     $container = $blobStore->read('bar');
     $container->set('one', 1001);
     $blobStore->save($container);
     $container = $blobStore->read('foo');
     $container->set('one', 42);
     $blobStore->save($container);
     $this->assertTrue($blobStore->exists('bar'));
     $this->assertTrue($blobStore->exists('foo'));
     sleep(5);
     $this->assertFalse($blobStore->exists('bar'));
     $this->assertFalse($blobStore->exists('foo'));
 }
 private function appendToList($id, $subject)
 {
     // Store the id with the main subject
     $container = $this->blobStore->read($this->getHashFrom($subject));
     // Use the id as key to avoid unnecessary duplicate entries when
     // employing append
     $container->append('list', array($id => true));
     $this->blobStore->save($container);
 }
 private function addToLinkedList($contextPage, $queryId)
 {
     // Ensure that without QueryDependencyLinksStore being enabled recorded
     // subjects related to a query can be discoverable and purged separately
     $container = $this->blobStore->read($this->getHashFrom($contextPage));
     // If a subject gets purged the the linked list of queries associated
     // with that subject allows for an immediate associated removal
     $container->addToLinkedList($this->getHashFrom($queryId));
     $this->blobStore->save($container);
 }
 /**
  * @since 2.5
  */
 public function saveStats()
 {
     $container = $this->blobStore->read(md5($this->statsdId . self::VERSION));
     foreach ($this->stats as $key => $value) {
         $old = $container->has($key) ? $container->get($key) : 0;
         if ($this->operations[$key] === self::STATS_INIT && $old != 0) {
             $value = $old;
         }
         if ($this->operations[$key] === self::STATS_INCR) {
             $value = $old + $value;
         }
         // Use as-is
         // $this->operations[$key] === self::STATS_SET
         if ($this->operations[$key] === self::STATS_MEDIAN) {
             $value = $old > 0 ? ($old + $value) / 2 : $value;
         }
         $container->set($key, $value);
     }
     $this->blobStore->save($container);
     $this->stats = array();
 }
Example #6
0
 public function testDropDoesNothing()
 {
     $this->cache->expects($this->never())->method('fetch');
     $this->cache->expects($this->never())->method('delete');
     $instance = new BlobStore('Foo', $this->cache);
     $instance->drop();
 }
 private function registerCallbackHandlersByConstructedInstance($callbackLoader)
 {
     /**
      * @var BlobStore
      */
     $callbackLoader->registerCallback('BlobStore', function ($namespace, $cacheType = null, $ttl = 0) use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('BlobStore', '\\Onoi\\BlobStore\\BlobStore');
         $cacheFactory = $callbackLoader->load('CacheFactory');
         $blobStore = new BlobStore($namespace, $cacheFactory->newMediaWikiCompositeCache($cacheType));
         $blobStore->setNamespacePrefix($cacheFactory->getCachePrefix());
         $blobStore->setExpiryInSeconds($ttl);
         $blobStore->setUsageState($cacheType !== CACHE_NONE && $cacheType !== false);
         return $blobStore;
     });
     /**
      * @var CachedQueryResultPrefetcher
      */
     $callbackLoader->registerCallback('CachedQueryResultPrefetcher', function ($cacheType = null) use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('CachedQueryResultPrefetcher', '\\SMW\\CachedQueryResultPrefetcher');
         $settings = $callbackLoader->load('Settings');
         $cacheType = $cacheType === null ? $settings->get('smwgQueryResultCacheType') : $cacheType;
         $cachedQueryResultPrefetcher = new CachedQueryResultPrefetcher($callbackLoader->load('Store'), $callbackLoader->singleton('QueryFactory'), $callbackLoader->create('BlobStore', CachedQueryResultPrefetcher::CACHE_NAMESPACE, $cacheType, $settings->get('smwgQueryResultCacheLifetime')), $callbackLoader->singleton('TransientStatsdCollector', CachedQueryResultPrefetcher::STATSD_ID));
         $cachedQueryResultPrefetcher->setLogger($callbackLoader->singleton('MediaWikiLogger'));
         $cachedQueryResultPrefetcher->setNonEmbeddedCacheLifetime($settings->get('smwgQueryResultNonEmbeddedCacheLifetime'));
         return $cachedQueryResultPrefetcher;
     });
     /**
      * @var CachedPropertyValuesPrefetcher
      */
     $callbackLoader->registerCallback('CachedPropertyValuesPrefetcher', function ($cacheType = null, $ttl = 604800) use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('CachedPropertyValuesPrefetcher', '\\SMW\\CachedPropertyValuesPrefetcher');
         $cachedPropertyValuesPrefetcher = new CachedPropertyValuesPrefetcher($callbackLoader->load('Store'), $callbackLoader->load('BlobStore', CachedPropertyValuesPrefetcher::CACHE_NAMESPACE, $cacheType, $ttl));
         return $cachedPropertyValuesPrefetcher;
     });
     /**
      * @var TransientStatsdCollector
      */
     $callbackLoader->registerCallback('TransientStatsdCollector', function ($id) use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('TransientStatsdCollector', '\\SMW\\TransientStatsdCollector');
         // Explicitly use the DB to access a SqlBagOstuff instance
         $cacheType = CACHE_DB;
         $ttl = 0;
         $transientStatsdCollector = new TransientStatsdCollector($callbackLoader->create('BlobStore', TransientStatsdCollector::CACHE_NAMESPACE, $cacheType, $ttl), $id);
         return $transientStatsdCollector;
     });
     /**
      * @var PropertySpecificationLookup
      */
     $callbackLoader->registerCallback('PropertySpecificationLookup', function () use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('PropertySpecificationLookup', '\\SMW\\PropertySpecificationLookup');
         $propertySpecificationLookup = new PropertySpecificationLookup($callbackLoader->singleton('CachedPropertyValuesPrefetcher'), $callbackLoader->singleton('InMemoryPoolCache')->getPoolCacheById(PropertySpecificationLookup::POOLCACHE_ID));
         // Uses the language object selected in user preferences. It is one
         // of two global language objects
         $propertySpecificationLookup->setLanguageCode(Localizer::getInstance()->getUserLanguage()->getCode());
         return $propertySpecificationLookup;
     });
     /**
      * @var PropertyHierarchyLookup
      */
     $callbackLoader->registerCallback('PropertyHierarchyLookup', function () use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('PropertyHierarchyLookup', '\\SMW\\PropertyHierarchyLookup');
         $propertyHierarchyLookup = new PropertyHierarchyLookup($callbackLoader->load('Store'), $callbackLoader->singleton('InMemoryPoolCache')->getPoolCacheById(PropertyHierarchyLookup::POOLCACHE_ID));
         $propertyHierarchyLookup->setSubcategoryDepth($callbackLoader->load('Settings')->get('smwgQSubcategoryDepth'));
         $propertyHierarchyLookup->setSubpropertyDepth($callbackLoader->load('Settings')->get('smwgQSubpropertyDepth'));
         return $propertyHierarchyLookup;
     });
     /**
      * @var PropertyLabelFinder
      */
     $callbackLoader->registerCallback('PropertyLabelFinder', function () use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('PropertyLabelFinder', '\\SMW\\PropertyLabelFinder');
         $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage();
         $propertyLabelFinder = new PropertyLabelFinder($callbackLoader->load('Store'), $extraneousLanguage->getPropertyLabels(), $extraneousLanguage->getCanonicalPropertyLabels());
         return $propertyLabelFinder;
     });
     /**
      * @var TransitionalDiffStore
      */
     $callbackLoader->registerCallback('TransitionalDiffStore', function () use($callbackLoader) {
         $callbackLoader->registerExpectedReturnType('TransitionalDiffStore', '\\SMW\\SQLStore\\TransitionalDiffStore');
         $cacheFactory = $callbackLoader->load('CacheFactory');
         $cacheType = null;
         $transitionalDiffStore = new TransitionalDiffStore($cacheFactory->newMediaWikiCompositeCache($cacheType), $cacheFactory->getCachePrefix());
         $transitionalDiffStore->setLogger($callbackLoader->singleton('MediaWikiLogger'));
         return $transitionalDiffStore;
     });
 }
Example #8
0
 public function testDeleteMembersOfLinkedListAsWell()
 {
     $linkedContainer = serialize(array('@linkedList' => array('a42b' => true)));
     $this->cache->expects($this->once())->method('contains')->with($this->equalTo('blobstore:Foo:Bar'))->will($this->returnValue(true));
     $this->cache->expects($this->once())->method('fetch')->will($this->returnValue($linkedContainer));
     $this->cache->expects($this->at(2))->method('delete')->with($this->equalTo('blobstore:Foo:a42b'));
     $this->cache->expects($this->at(3))->method('delete')->with($this->equalTo('blobstore:Foo:Bar'));
     $instance = new BlobStore('Foo', $this->cache);
     $instance->delete('Bar');
 }
 /**
  * @since 2.3
  *
  * @return CachedValueLookupStore
  */
 public function newCachedValueLookupStore()
 {
     $circularReferenceGuard = new CircularReferenceGuard('vl:store');
     $circularReferenceGuard->setMaxRecursionDepth(2);
     $cacheFactory = ApplicationFactory::getInstance()->newCacheFactory();
     $blobStore = new BlobStore('smw:vl:store', $cacheFactory->newMediaWikiCompositeCache($GLOBALS['smwgValueLookupCacheType']));
     // If CACHE_NONE is selected, disable the usage
     $blobStore->setUsageState($GLOBALS['smwgValueLookupCacheType'] !== CACHE_NONE);
     $blobStore->setExpiryInSeconds($GLOBALS['smwgValueLookupCacheLifetime']);
     $blobStore->setNamespacePrefix($cacheFactory->getCachePrefix());
     $cachedValueLookupStore = new CachedValueLookupStore($this->store, $blobStore);
     $cachedValueLookupStore->setValueLookupFeatures($GLOBALS['smwgValueLookupFeatures']);
     $cachedValueLookupStore->setCircularReferenceGuard($circularReferenceGuard);
     return $cachedValueLookupStore;
 }