From beb89065575e9e912187f6af2541fea62a2f2234 Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Tue, 1 Nov 2011 18:31:04 +0000 Subject: [PATCH] Re-apply Vitaliy Filippov's patch from Bug #29283 with a modification to make it work when no ACCEL cache is available. --- includes/AutoLoader.php | 1 + includes/LocalisationCache.php | 66 ++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 2f072121db..5ac74a1f3b 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -127,6 +127,7 @@ $wgAutoloadLocalClasses = array( 'IndexPager' => 'includes/Pager.php', 'Interwiki' => 'includes/interwiki/Interwiki.php', 'IP' => 'includes/IP.php', + 'LCStore_Accel' => 'includes/LocalisationCache.php', 'LCStore_CDB' => 'includes/LocalisationCache.php', 'LCStore_DB' => 'includes/LocalisationCache.php', 'LCStore_Null' => 'includes/LocalisationCache.php', diff --git a/includes/LocalisationCache.php b/includes/LocalisationCache.php index f76ae11a37..591f9732f9 100644 --- a/includes/LocalisationCache.php +++ b/includes/LocalisationCache.php @@ -159,8 +159,16 @@ class LocalisationCache { case 'db': $storeClass = 'LCStore_DB'; break; + case 'accel': + $storeClass = 'LCStore_Accel'; + break; case 'detect': - $storeClass = $wgCacheDirectory ? 'LCStore_CDB' : 'LCStore_DB'; + try { + $c = wfGetCache( CACHE_ACCEL ); + $storeClass = 'LCStore_Accel'; + } catch( Exception $c ) { + $storeClass = $wgCacheDirectory ? 'LCStore_CDB' : 'LCStore_DB'; + } break; default: throw new MWException( @@ -348,7 +356,9 @@ class LocalisationCache { } $deps = $this->store->get( $code, 'deps' ); - if ( $deps === null ) { + $keys = $this->store->get( $code, 'list', 'messages' ); + // 'list:messages' sometimes expires separately of 'deps' in LCStore_Accel + if ( $deps === null || $keys === null ) { wfDebug( __METHOD__."($code): cache missing, need to make one\n" ); return true; } @@ -829,6 +839,56 @@ interface LCStore { function set( $key, $value ); } +/** + * LCStore implementation which uses PHP accelerator to store data. + * This will work if one of XCache, eAccelerator, or APC cacher is configured. + * (See ObjectCache.php) + */ +class LCStore_Accel implements LCStore { + var $currentLang; + var $keys; + + public function __construct() { + $this->cache = wfGetCache( CACHE_ACCEL ); + } + + public function get( $code, $key ) { + $k = wfMemcKey( 'l10n', $code, 'k', $key ); + $r = $this->cache->get( $k ); + if ( $r === false ) return null; + return $r; + } + + public function startWrite( $code ) { + $k = wfMemcKey( 'l10n', $code, 'l' ); + $keys = $this->cache->get( $k ); + if ( $keys ) { + foreach ( $keys as $k ) { + $this->cache->delete( $k ); + } + } + $this->currentLang = $code; + $this->keys = array(); + } + + public function finishWrite() { + if ( $this->currentLang ) { + $k = wfMemcKey( 'l10n', $this->currentLang, 'l' ); + $this->cache->set( $k, array_keys( $this->keys ) ); + } + $this->currentLang = null; + $this->keys = array(); + } + + public function set( $key, $value ) { + if ( $this->currentLang ) { + $k = wfMemcKey( 'l10n', $this->currentLang, 'k', $key ); + $this->keys[$k] = true; + $this->cache->set( $k, $value ); + } + } +} + /** * LCStore implementation which uses the standard DB functions to store data. * This will work on any MediaWiki installation. @@ -1126,4 +1186,4 @@ class LocalisationCache_BulkLoad extends LocalisationCache { $this->unload( $code ); } } -} +} \ No newline at end of file -- 2.20.1