- static function pagesInNs( $ns ) {
- if ( !isset( self::$pageCount[$ns] ) ) {
- $dbr = wfGetDB( DB_REPLICA );
- self::$pageCount[$ns] = (int)$dbr->selectField(
- 'page',
- 'COUNT(*)',
- [ 'page_namespace' => $ns ],
- __METHOD__
- );
- }
- return self::$pageCount[$ns];
+ public static function pagesInNs( $ns ) {
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'SiteStats', 'page-in-namespace', $ns ),
+ $cache::TTL_HOUR,
+ function ( $oldValue, &$ttl, array &$setOpts ) use ( $ns ) {
+ $dbr = self::getLB()->getConnection( DB_REPLICA );
+ $setOpts += Database::getCacheSetOptions( $dbr );
+
+ return (int)$dbr->selectField(
+ 'page',
+ 'COUNT(*)',
+ [ 'page_namespace' => $ns ],
+ __METHOD__
+ );
+ },
+ [ 'pcTTL' => $cache::TTL_PROC_LONG ]
+ );