From d355471f1aecc0d475eef39d22b7946f52336b5d Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 26 Oct 2015 00:59:10 -0700 Subject: [PATCH] Make DateFormatter::getInstance use APC Change-Id: Idfff805903bffcdd6ff8f2a3c1331ca63476933e --- includes/parser/DateFormatter.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index ef295ab217..78f7775f76 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -124,18 +124,23 @@ class DateFormatter { * Defaults to the site content language * @return DateFormatter */ - public static function &getInstance( $lang = null ) { - global $wgMemc, $wgContLang; - static $dateFormatter = false; + public static function getInstance( $lang = null ) { + global $wgContLang, $wgMainCacheType; + $lang = $lang ? wfGetLangObj( $lang ) : $wgContLang; - $key = wfMemcKey( 'dateformatter', $lang->getCode() ); + $cache = ObjectCache::newAccelerator( $wgMainCacheType ); + + static $dateFormatter = false; if ( !$dateFormatter ) { - $dateFormatter = $wgMemc->get( $key ); - if ( !$dateFormatter ) { - $dateFormatter = new DateFormatter( $lang ); - $wgMemc->set( $key, $dateFormatter, 3600 ); - } + $dateFormatter = $cache->getWithSetCallback( + $cache->makeKey( 'dateformatter', $lang->getCode() ), + 3600, + function () use ( $lang ) { + return new DateFormatter( $lang ); + } + ); } + return $dateFormatter; } -- 2.20.1