public function testfetchListFromCache() { $expectedCachedItem = array('time' => 42, 'list' => serialize(array('Foo'))); $listLookup = $this->getMockBuilder('\\SMW\\SQLStore\\ListLookup')->disableOriginalConstructor()->getMock(); $listLookup->expects($this->atLeastOnce())->method('getLookupIdentifier')->will($this->returnValue('Bar')); $cache = $this->getMockBuilder('\\Onoi\\Cache\\Cache')->disableOriginalConstructor()->getMock(); $cache->expects($this->once())->method('contains')->with($this->stringContains('cacheprefix-foobar:smw:listlookup-cache:'))->will($this->returnValue(true)); $cache->expects($this->once())->method('fetch')->will($this->returnValue($expectedCachedItem)); $cacheOptions = new \stdClass(); $cacheOptions->useCache = true; $instance = new CachedListLookup($listLookup, $cache, $cacheOptions); $instance->setCachePrefix('cacheprefix-foobar'); $this->assertEquals(array('Foo'), $instance->fetchList()); $this->assertEquals(42, $instance->getTimestamp()); $this->assertEquals('Bar', $instance->getLookupIdentifier()); $this->assertTrue($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; }