Thread:Extension talk:Lingo/Caching the LingoTree

I encountered some performance issues while using Lingo in combination with Semantic Glossary. The glossary does not change all that often, but it is still retrieved and rebuilt for every page view. This had severe impact on our loading times (we're talking about seconds here).

I added some caching logic to Lingo to LingoParser::buildLingo that solved this for us. The LingoTree is cached for 15 mins before it is rebuilt.

protected function buildLingo { wfProfileIn( __METHOD__ );

global $wgMemc; // Try cache first $cachekey = wfMemcKey( 'lingo', 'lingotree' ); $cachedLingoTree = $wgMemc->get( $cachekey ); if($cachedLingoTree != '') { $this->mLingoTree = $cachedLingoTree; } else { $this->mLingoTree = new LingoTree; $backend = &$this->mLingoBackend; // assemble the result array while ( $elementData = $backend->next ) { $this->mLingoTree->addTerm( $elementData[LingoElement::ELEMENT_TERM], $elementData ); }			$wgMemc->set($cachekey, $this->mLingoTree, 60*15); }		wfProfileOut( __METHOD__ ); }

I'm planning to make the caching optional and the cache expiry time configurable, and to check this code in to Subversion. Any objections?