From 3dfde951a7fdbe7d04a5ecaa8b7a52a816f690fd Mon Sep 17 00:00:00 2001 From: aude Date: Sat, 22 Nov 2014 15:14:41 -0500 Subject: [PATCH] Inject cache as constructor param of SiteSQLStore Change-Id: If1d08d4f3451b72d7d4d1c443cf2c82842ffd20f --- includes/site/SiteSQLStore.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/includes/site/SiteSQLStore.php b/includes/site/SiteSQLStore.php index fde22f1738..c1a350d854 100644 --- a/includes/site/SiteSQLStore.php +++ b/includes/site/SiteSQLStore.php @@ -51,15 +51,25 @@ class SiteSQLStore implements SiteStore { */ private $cacheTimeout = 3600; + /** + * @var BagOStuff + */ + private $cache; + /** * @since 1.21 * * @param ORMTable|null $sitesTable + * @param BagOStuff|null $cache * * @return SiteStore */ - public static function newInstance( ORMTable $sitesTable = null ) { - return new static( $sitesTable ); + public static function newInstance( ORMTable $sitesTable = null, BagOStuff $cache = null ) { + if ( $cache === null ) { + $cache = wfGetMainCache(); + } + + return new static( $cache, $sitesTable ); } /** @@ -67,13 +77,15 @@ class SiteSQLStore implements SiteStore { * * @since 1.21 * + * @param BagOStuff $cache * @param ORMTable|null $sitesTable */ - protected function __construct( ORMTable $sitesTable = null ) { + protected function __construct( BagOStuff $cache, ORMTable $sitesTable = null ) { if ( $sitesTable === null ) { $sitesTable = $this->newSitesTable(); } + $this->cache = $cache; $this->sitesTable = $sitesTable; } @@ -123,8 +135,7 @@ class SiteSQLStore implements SiteStore { if ( $source === 'cache' ) { if ( $this->sites === null ) { - $cache = wfGetMainCache(); - $sites = $cache->get( $this->getCacheKey() ); + $sites = $this->cache->get( $this->getCacheKey() ); if ( is_object( $sites ) ) { $this->sites = $sites; @@ -257,8 +268,7 @@ class SiteSQLStore implements SiteStore { } } - $cache = wfGetMainCache(); - $cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout ); + $this->cache->set( $this->getCacheKey(), $this->sites, $this->cacheTimeout ); wfProfileOut( __METHOD__ ); } @@ -374,8 +384,7 @@ class SiteSQLStore implements SiteStore { public function reset() { wfProfileIn( __METHOD__ ); // purge cache - $cache = wfGetMainCache(); - $cache->delete( $this->getCacheKey() ); + $this->cache->delete( $this->getCacheKey() ); $this->sites = null; wfProfileOut( __METHOD__ ); -- 2.20.1