cache = $cache; $this->catManager = $catManager; } /** * @param string $cat * @return string */ private function makeKey( $cat ) { return $this->cache->makeKey( 'linter', 'total', $cat ); } /** * Get the totals for every category in the database * * @return array */ public function getTotals() { $cats = $this->catManager->getVisibleCategories(); $fetchedTotals = false; $totals = []; foreach ( $cats as $cat ) { $totals[$cat] = $this->cache->getWithSetCallback( $this->makeKey( $cat ), WANObjectCache::TTL_INDEFINITE, static function ( $oldValue, &$ttl, &$setOpts, $oldAsOf ) use ( $cat, &$fetchedTotals ) { $setOpts += MWDatabase::getCacheSetOptions( wfGetDB( DB_REPLICA ) ); if ( $fetchedTotals === false ) { $fetchedTotals = ( new Database( 0 ) )->getTotals(); } return $fetchedTotals[$cat]; }, [ 'checkKeys' => [ $this->cache->makeKey( 'linter', 'totals' ), $this->makeKey( $cat ), ], 'lockTSE' => 30, ] ); } return $totals; } /** * Have a single category be recalculated * * @param string $cat category name */ public function touchCategoryCache( $cat ) { $this->cache->touchCheckKey( $this->makeKey( $cat ) ); } /** * Have all categories be recalculated */ public function touchAllCategoriesCache() { $this->cache->touchCheckKey( $this->cache->makeKey( 'linter', 'totals' ) ); } }