* @internal documentation reviewed 15 Mar 2010
*/
class Title {
- /** @name Static cache variables */
- // @{
- static private $titleCache = array();
- // @}
+ /** @var MapCacheLRU */
+ static private $titleCache = null;
/**
* Title::newFromText maintains a cache to avoid expensive re-normalization of
throw new MWException( 'Title::newFromText given an object' );
}
+ $cache = self::getTitleCache();
+
/**
* Wiki pages often contain multiple links to the same page.
* Title normalization and parsing can become expensive on
*
* In theory these are value objects and won't get changed...
*/
- if ( $defaultNamespace == NS_MAIN && isset( Title::$titleCache[$text] ) ) {
- return Title::$titleCache[$text];
+ if ( $defaultNamespace == NS_MAIN && $cache->has( $text ) ) {
+ return $cache->get( $text );
}
# Convert things like é ā or 〗 into normalized (bug 14952) text
$t->mDbkeyform = str_replace( ' ', '_', $filteredText );
$t->mDefaultNamespace = $defaultNamespace;
- static $cachedcount = 0;
if ( $t->secureAndSplit() ) {
if ( $defaultNamespace == NS_MAIN ) {
- if ( $cachedcount >= self::CACHE_MAX ) {
- # Avoid memory leaks on mass operations...
- Title::$titleCache = array();
- $cachedcount = 0;
- }
- $cachedcount++;
- Title::$titleCache[$text] =& $t;
+ $cache->set( $text, $t );
}
return $t;
} else {
}
}
+ /**
+ * @return MapCacheLRU
+ */
+ private static function getTitleCache() {
+ if ( self::$titleCache == null ) {
+ self::$titleCache = new MapCacheLRU( self::CACHE_MAX );
+ }
+ return self::$titleCache;
+ }
+
/**
* Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
* Uses $wgContentHandlerUseDB to determine whether to include page_content_model.
$this->cache[$key] = $value;
}
+ /**
+ * Check if a key exists
+ *
+ * @param $key string
+ * @return bool
+ */
+ public function has( $key ) {
+ return isset( $this->cache[$key] );
+ }
+
/**
* Get the value for a key.
* This returns null if the key is not set.
* If the item is already set, it will be pushed to the top of the cache.
*
* @param $key string
- * @param $prop string
* @return mixed
*/
public function get( $key ) {