public function testClearCache() { $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock(); $connection->expects($this->once())->method('selectRow')->will($this->returnValue(false)); $instance = new DataItemByIdFinder($connection, 'foo'); $instance->saveToCache(42, 'Foo#0##'); $instance->getDataItemForId(42); $instance->clear(); $instance->getDataItemForId(42); }
/** * Add or modify a cache entry. The key consists of the * parameters $title, $namespace, $interwiki, and $subobject. The * cached data is $id and $sortkey. * * @since 1.8 * @param string $title * @param integer $namespace * @param string $interwiki * @param string $subobject * @param integer $id * @param string $sortkey */ public function setCache($title, $namespace, $interwiki, $subobject, $id, $sortkey) { if (strpos($title, ' ') !== false) { throw new MWException("Somebody tried to use spaces in a cache title! ({$title})"); } $hashKey = HashBuilder::createHashIdFromSegments($title, $namespace, $interwiki, $subobject); if ($namespace == SMW_NS_PROPERTY && $interwiki === '' && $subobject === '') { $this->checkPropertySizeLimit(); $this->prop_ids[$title] = $id; $this->prop_sortkeys[$title] = $sortkey; } else { $this->checkRegularSizeLimit(); $this->regular_ids[$hashKey] = $id; $this->regular_sortkeys[$hashKey] = $sortkey; } $this->dataItemByIdFinder->saveToCache($id, $hashKey); if ($interwiki == SMW_SQL3_SMWREDIIW) { // speed up detection of redirects when fetching IDs $this->setCache($title, $namespace, '', $subobject, 0, ''); } }