objectcache: Introduce IExpiringStore for convenient TTL constants
[lhc/web/wiklou.git] / includes / parser / DateFormatter.php
index 3db8d1e..5ffca23 100644 (file)
@@ -33,7 +33,7 @@ class DateFormatter {
        public $regexes, $pDays, $pMonths, $pYears;
        public $rules, $xMonths, $preferences;
 
-       protected $lang;
+       protected $lang, $mLinked;
 
        const ALL = -1;
        const NONE = 0;
@@ -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() ),
+                               $cache::TTL_HOUR,
+                               function () use ( $lang ) {
+                                       return new DateFormatter( $lang );
+                               }
+                       );
                }
+
                return $dateFormatter;
        }