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')); }
public function testTransferExpiry() { $instance = new BlobStore('Foo', $this->cache); $instance->setExpiryInSeconds(42); $container = $instance->read('Bar'); $this->assertEquals(42, $container->getExpiry()); }
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; }); }
/** * @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; }