public function testRetrieveResultListFromInjectedListLookup() { $expectedCacheItem = array('time' => 42, 'list' => serialize(array('Foo'))); $listLookup = $this->getMockBuilder('\\SMW\\SQLStore\\ListLookup')->disableOriginalConstructor()->getMock(); $listLookup->expects($this->once())->method('fetchList')->will($this->returnValue(array('Foo'))); $listLookup->expects($this->once())->method('getTimestamp')->will($this->returnValue(42)); $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock(); $cache->expects($this->once())->method('save')->with($this->stringContains('lookup-cache'), $this->anything($expectedCacheItem), $this->equalTo(1001)); $cacheOptions = new \stdClass(); $cacheOptions->useCache = false; $cacheOptions->ttl = 1001; $instance = new CachedListLookup($listLookup, $cache, $cacheOptions); $this->assertEquals(array('Foo'), $instance->fetchList()); $this->assertEquals(42, $instance->getTimestamp()); $this->assertFalse($instance->isCached()); }
/** * @since 2.2 * * @param ListLookup $listLookup * @param boolean $useCache * @param integer $cacheExpiry * * @return ListLookup */ public function newCachedListLookup(ListLookup $listLookup, $useCache, $cacheExpiry) { $cacheFactory = ApplicationFactory::getInstance()->newCacheFactory(); $cacheOptions = $cacheFactory->newCacheOptions(array('useCache' => $useCache, 'ttl' => $cacheExpiry)); $cachedListLookup = new CachedListLookup($listLookup, $cacheFactory->newMediaWikiCompositeCache($cacheFactory->getMainCacheType()), $cacheOptions); $cachedListLookup->setCachePrefix($cacheFactory->getCachePrefix()); return $cachedListLookup; }